I'm fairly new with CakePHP and images so bear with me. You can assume I'm using the latest version.
I'm trying to build an Android application which can display images retrieved from the server.
Suppose I have an image in the assets folder called football.jpg. How would I store this in the database and then how would I output this to the Android application? Do I send only the link or do I send the whole image over? If it is just the link, does this mean I would have to reconnect to the server with the link and then get the image? Sorry if this doesn't make sense. Still trying to get my head around it.
Just a word of caution, it's probably better to store the file on the server's file system and store the path to the file in the database. The reason behind this is that BLOBs are stored in a different area on the file system to all your other typical data and in terms of retrieval, its not a great deal faster.
Here's a link to what I mean: Store pictures as files or in the database for a web app?
With regards to returning it to your Android app, you can send files in the response object (http://book.cakephp.org/2.0/en/controllers/request-response.html#cake-response-file):
public function sendFile($id) {
$file = $this->Attachment->getFile($id);
$this->response->file($file['path']);
//Return reponse object to prevent controller from trying to render a view
return $this->response;
}
This should give you finer control over what files are returned to your client.
Related
I just wrote web services for wordpress like login, register, pass update, etc...
Now I want to user can upload images from iOS device and send this via web services(query string). I am not sure how to do this.
For login I just create a query string like http://example.com/apps/login.php?user=something&pass=something and get all the data in php file and then update the wordpress DB and return success message in json_encode.
But for images, how I can create the query string and how I can get those images in php file.
Thanks in advance...
But for images, how I can create the query string
You DO NOT! It's not a place for that. If you need data uploaded, do it right way using HTTP POST request with data payload.
I am creating an API-centric web application using PHP. I have read a lot of articles on API-centric arhitecture and design, but I have a problem related to file uploads.
Suppose I have an image and I want to upload it to the API server. How should I upload that image and how then to receive the link to that image?
Here is how I want to create it now:
Select an image using <input type="file"> on client www.domain.com
Upload it to the www.domain.com using POST with multipart/form-data
Send this image with PUT/POST API call to the api.domain.com
api.domain.com will save this image to another server like static.domain.com and will store image's id in the database
Then, when I will need this image, I can use GET API call to the api.domain.com and I will receive image's url (something like static.domain.com/image.jpg)
Aditional questions:
Is this approach the right one or I am doing completely wrong?
Will I need an aditional server to store uploaded files if my application will be small, or I can store files right on the API server?
If I will store images on same server as API server, won't it be strange if image urls will look like api.domain.com/image.jpg?
P.S: We can skip a lot of API-related things as I need only an idea on how to deal with file uploads.
You haven't really said what kind of API that you are going to be implementing here, so I assume that it is just a restful API.
Is this approach the right one or I am doing completely wrong?
No, I wouldn't say you're doing it wrong. You would essentially send the file using POST.
Will I need an aditional server to store uploaded files if my application will be small, or I can store files right on the API server?
Yes, it will allow you to store this on the same server, I don't see why not. I doubt that you will use a lot of storage, if the application is small.
If I will store images on same server as API server, won't it be strange if image urls will look like api.domain.com/image.jpg?
The api.domain.com/image.jpg technically is just the URL that you connect to the API with and GET/POST data. It does not mean the file is going to be that URL. The API could return like:
{
type: "IMG",
id: "1",
url: "example.com/uploads/image.jpg"
}
I hope this this helps, even a little!
So I did as suggested here.
But I'm still seeing some pretty slow responses when getting URLs for files stored in containers on cloudfiles.
The application I'm building has a portion where users can comment. Each user has a profile image which shows up next to their comment. The basic structure of the code is as follows:
1) Authenticate cloudfiles api
2) Open connection
3) Retrieve main users profile image
4) Retrieve all comments from database
4.1) Loop through users comments
4.2) Get container and file name from DB
4.3) Retrieve image from CloudFiles
5) Close connection
I have SNET as true and I am on a Rackspace server but, it seems to crawl in comparison to when I stored them directly on the server. Also the reason I am not storing the public url in the database is due to the user being able to change their image and me wanting to store past images, therefore not overwriting the past image. I could store each past image's url as well as the new images and probably will do that but, wanted to see how fast I could get it prior to doing that.
The reason I am hesitant to go straight to storing each images public url is because on another portion of the site I am going to use Temp URLs for some secure files and am trying to see if I can fix the performance in general.
Any suggestions are appreciated!
Thanks
I'm building a MYSQL database driven website on a AWS EC2 instance. Users can submit their data and we will automatically create a web page for them. The webpage will display their submitted data including a photo. Upon original submission of the user's data, we store the photo in S3 using AWSSDKforPHP. When their information is approved by an administrator a webpage is created via a php script.
I've tried the method of generating a signed url. This however requires a expiration time. Is there a way around this? It also includes your access and secret key in the request. Not sure if that is the most secure way to do things. I'd like the method to be as secure as possible so I don't want to make the bucket public. Unless there is a way to make the stored images available only for viewing.
What's the best method to use in a situation like this? Thanks for your help!!
Basically URLs to amazon S3 buckets are s3.amazonaws/bucket_name/key_name all you need to do is make sure the content on those buckets is publicly available and that mime type for those keys is indeed image (image/jpeg or image/png)
I used this web tool to manage my site. I opend my bucket just to its ip and now i can control the restriction from the tool, for the basic viewer I gave read access only
I'm new to Android and would like to ask is it possible to save the files (incl. image, text etc) created within a app directly to the php server? Without saving it in any internal or external storage like SD card?
This is due to users are not allowed to access to the data once they offline.Users shall not kept anything to their personal device other than accessing it online by login in.
I have read through the passage of Data Storage in Android developer website. What was mentioned there is just the ways for data storage. Web server as the last options without having any examples.
Please advise and give a snippet if possible.
Another questions will be, in such a situation(save in server without saving in SD card). Any idea on how to keep the created data temporary if let's say the internet connection is down? And I do not wish to lost any data?
Please give some suggestion, if you have any for the problem.
You can definitely save data to a server and not ever write it to the local disk: Google is your friend and will provide examples such as this if you search for android POST http.
No exampele because nothiong is android specific here .
create webservice to store file send the data to webservices from device . in case of images send its ByteStream . example is here .