作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个脚本(适用于 Android 的 Phonegap)来发送从相册中选择的图像,但这对我来说很难。
按照我的脚本:
function onCapturePhoto(imageURI) {
var uri = encodeURI("https://www.myserver.com/webservices/uploadFoto.php");
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType = "text/jpeg";
var ft = new FileTransfer();
ft.upload(imageURI, uri, win, fail, options);
function win(r) {
console.log("Code: = " + r.responseCode);
console.log("Response: = " + r.response);
console.log("Sent: = " + r.bytesSent);
}
function fail(error) {
console.log("An error has occurred: Code = " + error.code);
console.log("upload error source: " + error.source);
console.log("upload error target: " + error.target);
}
}
function getPhoto() {
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 80,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : true,
targetWidth: 150,
encodingType: navigator.camera.EncodingType.JPEG
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
我收到以下错误:
发生错误:代码 = 1
上传错误来源:file:///storage/emulated/0/Android/data/mobi.monaca.debugger/cache/.Pic.jpg
上传错误目标:https://www.myserver.com/webservices/uploadFoto.php
我正在使用 Monaca 调试器。
最佳答案
上传图片代码错误:
options.mimeType = "text/jpeg";
将其更改为:
options.mimeType = "image/jpeg";
另一方面,Android 4.4 的一些有用的选项代码
options.chunkedMode = false;
options.headers = {Connection: "close"};
关于javascript - Phonegap - 将图像从 photogalery 上传到服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27221084/
我正在尝试创建一个脚本(适用于 Android 的 Phonegap)来发送从相册中选择的图像,但这对我来说很难。 按照我的脚本: function onCapturePhoto(imageURI)
我是一名优秀的程序员,十分优秀!