简体   繁体   English

从javaScript Phonegap上传文件的方法

[英]Ways to upload files from javaScript Phonegap

I am developing an Android application using phonegap and I need to know how upload a file (images and videos) through JavaScript. 我正在使用phonegap开发Android应用程序,我需要知道如何通过JavaScript上传文件(图片和视频)。

Can anybody help me with this?, give me any idea or something.. 有人可以帮我吗?给我任何想法或东西。

The application consume WCF Rest web services. 该应用程序使用WCF Rest Web服务。

Thanks! 谢谢!

Use the filetransfer API - http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileTransfer should do the trick :) 使用文件传输API- http: //docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileTransfer应该可以解决问题:)

Edit - To use the filetransfer you would do something like this.. 编辑-要使用文件传输,您将执行以下操作。

var options = new FileUploadOptions();
options.fileKey="photo";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";

var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

var ft = new FileTransfer();
ft.upload(fileURI, "http://some.server.com/upload.php", win, fail, options);

Make sure you're defining the fileURI. 确保您正在定义fileURI。 On your server you would be looking for a post with a name of "photo" or what ever you call the fileKey. 在您的服务器上,您正在寻找名称为“ photo”或您称之为fileKey的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM