Cordova PhoneGap文件上传3G
我目前遇到了一个非常恼人的PhoneGap问题。我创建了一个将图像上传到远程服务器(服务器运行PHP)的应用程序 当我通过WiFi上传图像时,该应用程序工作正常,但当我通过2G/3G上传相同的图像时,什么都没有发生。没有错误回调,没有成功回调,什么都没有发生 我尝试过不同的文件大小,包括一些非常小(约150kb)的文件,但这似乎没什么帮助。我试过Cordova版本2.5、2.6和2.7。该应用程序使用phonegap文档中的默认示例。应用程序代码为:Cordova PhoneGap文件上传3G,cordova,file-upload,upload,3g,Cordova,File Upload,Upload,3g,我目前遇到了一个非常恼人的PhoneGap问题。我创建了一个将图像上传到远程服务器(服务器运行PHP)的应用程序 当我通过WiFi上传图像时,该应用程序工作正常,但当我通过2G/3G上传相同的图像时,什么都没有发生。没有错误回调,没有成功回调,什么都没有发生 我尝试过不同的文件大小,包括一些非常小(约150kb)的文件,但这似乎没什么帮助。我试过Cordova版本2.5、2.6和2.7。该应用程序使用phonegap文档中的默认示例。应用程序代码为: var app = { // App
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
doStuff: function() {
navigator.camera.getPicture(app.uploadPhoto,
function(message) { alert('get picture failed'); },
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
},
uploadPhoto: function(imageURI) {
var options = new FileUploadOptions();
options.fileKey="files";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
params.pathname = "VARIABLE_FOR_SERVER";
params['file-type'] = 'image';
options.params = params;
try {
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("SERVER_URL_HERE"), app.win, app.fail, options, true);
} catch (err) {
console.log('catch error');
console.log(err);
}
},
win: function(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
},
fail: function(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
};
服务器上的$\u FILES变量为空。有没有人知道这里发生了什么,因为我正在疯狂地尝试修复/调试这个:D我有一个问题,现在已经解决了。是我的移动运营商更改了我的连接头。