Reputation: 63
I am trying to use the PhoneGap FileUploader plugin to upload an image from iPhone to my server
How do I use the uploadByUri
function exactly? I don't understand all the parameters...
FileUploader.prototype.uploadByUri("http://www.mysite.com/images/", imageURI,
params, fileKey, "myimage", "image/jpg", uploadSuccess, uploadFail, uploadProgress)
What do I use for for "params
" and "filekey
"? The read-me file says:
- fileKey Parameter name of the file
- params Object with key: value params to send to the server
Right now I am putting null
and get no errors, but there is no image in my destination folder.
Also, do you know if I can upload directly an image in base64-encoded string from the camera rather than an image from the album?
Thank you for your help.
Roberto
Upvotes: 2
Views: 4134
Reputation: 1447
The fileKey is the name of the file field that the server is expecting. So if you were uploading a file via a web app you would have an <input type="file" name="fileKey">
and the server would be looking for the "fileKey" to get the file data.
Params is unused I believe.
Uploading a base64 encoded image would be just like uploading a text file I assume. On the server you would need to convert it to an image file.
Upvotes: 1
Reputation: 83
Just to update. Phonegap now has a file api, which seems to do what the filuploader plugin does: http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html
Upvotes: 1
Reputation: 63
Well, it took me 3 days to figure out that FileUploader was not doing ftp uploads, and that the server destination was actually not a folder but a server-side script. I am going to answer my question in case someone else needs help.
Here is a barebone php script to save the image 'uploaded' by FileUploaded.
<?
// the actual uploaded image
$uploaded_image = $_FILES['image']['tmp_name'];
// the uploaded image name
$uploaded_image_name = $_FILES['image']['name'];
// location where you want to save the image
$saved_image = "my_images/$uploaded_image_name";
// saves the image
move_uploaded_file($uploaded_image, $saved_image);
?>
Make sure to create a folder where your php file is ("my_images" in this example).
To trigger the FileUploader plugin:
window.plugins.FileUploader.uploadByUri("http://www.yourserver.com/your_php_script.php", your_actual_image, null, "image", "my_image.jpg", "image/jpg", uploadSuccess, uploadFail, uploadProgress);
Notice that my fileKey parameter is "image" because I am uploading an image. This matches $_FILES['image']['tmp_name']
and $_FILES['image']['name']
.
Make sure to copy 'fileUploader.js' in your www folder, but 'fileUploader.h' and 'fileUploader.m' in your Plugins folder. (Do not copy the FileUploader folder itself).
Roberto
Upvotes: 1