我正在尝试将图像上传到我的FTP。
我的科尔多瓦文件传输看起来像
$scope.upload =function(){
var options = {
fileKey: "file",
fileName: "gopi",
chunkedMode: false,
mimeType: "image/jpeg",
params : {'user_token':'Chandru@123', 'user_email':'wepopusers'} // directory represents remote directory, fileName represents final remote file name
};
console.log(options);
$cordovaFileTransfer.upload('ftp://308.3d8.myftpupload.com/', MyService.getImgPath(), options)
.then(function(result) {
// Success!
console.log(result);
console.log("SUCCESS: " + JSON.stringify(result.response));
alert('ftp success');
}, function(err) {
// Error
console.log(err);
alert('ftp fail');
console.log("ERROR: " + JSON.stringify(err));
}, function (progress) {
// constant progress updates
console.log(progress);
});
};
我对cordova文件的错误功能的响应如下
FileTransferError {代码:2,来源:“ file:///storage/sdcard0/Android/data/com.ionicframework.camera108827/cache/1462186990291.jpg”,目标:“ ftp://308.3d8.myftpupload.com/ ” ,http_status:null,body:null…} body:nullcode:2exception:nullhttp_status:nullsource:“ file:///storage/sdcard0/Android/data/com.ionicframework.camera108827/cache/1462186990291.jpg”目标:“ ftp ://308.3d8.myftpupload.com/ “ proto:Object
我有一个TakePicture按钮,它将把图片并显示给用户,而且我还有一个函数使用cordovafiletransfer $ scope.upload上传。
我的ftp主机是ftp://308.3d8.myftpupload.com/
用户名,密码是在我的编码中指定的,我有一个名为gopi的文件夹名称,我的图像应该存储在该文件夹中。
我拍摄的图像的路径在imageURI参数中,因此我使用了服务来设置路径。
我感到困惑的步骤
1)我无法理解Cordova文件传输插件中的var options对象。
2)远程调试时没有任何错误,但我只是在我的cordova文件传输中调用了错误功能。
如何使用IONIC将拍摄的图像更新为FTP
更新
多亏了甘地(Gandhi)的回答https://github.com/xfally/cordova-plugin-ftp,我才得以成功地连接到ftp而没有多方面的问题。
但是仍然面临错误
$ window.cordova.plugin.ftp.upload(“ / ping”,“ / gopi / ping”,function(percent){
我不知道在第二个论点中要做什么。
$ window.cordova.plugin.ftp.upload(“ / default.prop”,“ /gopi/default.prop”,function(percent){
以上行成功完全发布到我的ftp,但是我无法发布存储在ping变量中的图像。
文件传输插件的官方文档中提供了第一个问题的答案。摘录如下,
options: Optional parameters (Object). Valid keys:
fileKey: The name of the form element. Defaults to file. (DOMString)
fileName: The file name to use when saving the file on the server. Defaults to image.jpg. (DOMString)
httpMethod: The HTTP method to use - either PUT or POST. Defaults to POST. (DOMString)
mimeType: The mime type of the data to upload. Defaults to image/jpeg. (DOMString)
params: A set of optional key/value pairs to pass in the HTTP request. (Object, key/value - DOMString)
chunkedMode: Whether to upload the data in chunked streaming mode. Defaults to true. (Boolean)
headers: A map of header name/header values. Use an array to specify more than one value. On iOS, FireOS, and Android, if a header named Content-Type is present, multipart form data will NOT be used. (Object)
查看此链接以获取更多信息。
对于第二个问题,请尝试在错误回调函数中获取错误代码,并尝试缩小问题范围。
更新:我想使用文件传输插件无法进行ftp上传。插件定义本身说明"The FileTransfer object provides a way to upload files using an HTTP multi-part POST or PUT request, and to download files"
对于ftp上传的ftp客户端,您可能必须查看此内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句