gpt4 book ai didi

javascript - Phonegap - 将图像从 photogalery 上传到服务器时出错

转载 作者:行者123 更新时间:2023-11-29 20:57:24 28 4
gpt4 key购买 nike

我正在尝试创建一个脚本(适用于 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com