【发布时间】:2015-02-14 20:41:22
【问题描述】:
我需要在后台发送多张图片和一些数据到服务器。
我正在为我的 android 应用程序使用 ionicframework(带有 angularjs)。 我正在使用 angular-file-upload (directive),以下代码是我的工厂:
if(angular.isArray(arrPictures) && arrPictures.length > 0) {
var files = [];
for(var i=0; i<arrPictures.length; i++) {
files.push(arrPictures[i].photo); //it is like file://my_path/myImage.jpg
}
$upload.upload({
url: API_POST_ANSWER,
method: 'POST',
data: {
"idSurvey": idSurvey,
"idOAM": idOAM,
"idOPM": idOPM,
"score": score,
"date": date,
"answerJson": answersJson,
"address": address,
"latitude": latitude,
"longitude": longitude
},
file: files,
fileFormDataName: "pictures"
}).progress(function (evt) {
//progress
alert('progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ evt.config.file.name);
}).success(function (data, status, headers, config) {
// file is uploaded successfully
alert('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);
}).error(function (ex) {
//error
alert("error");
alert(ex);
});
}
现在我遇到了一个问题,因为服务器获取的是字符串(路径字符串)而不是文件 我的问题是“如何将路径字符串转换为文件对象以将其正确发送到服务器?”
【问题讨论】:
-
您使用的是什么服务器?您是否确保服务器实际上可以正确接收文件?
标签: javascript angularjs file-upload ionic-framework