【发布时间】:2023-03-13 09:07:01
【问题描述】:
我正在尝试将图像从 android 设备库上传到服务器。但是选择的图片扩展名不是jpg/png/gif的形式。它以一些未知名称存储为“image%3A55766”。有人可以帮助我实现这一点。提前致谢。相同的代码在 iOS 设备上运行良好。我试过这个到现在。
<script>
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 25,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
});
}
function onPhotoURISuccess(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://server.net/project/php/uploads.php"), win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
</script>
document.getElementById('gal1').innerHTML='<a href="javascript:void(0)" onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM)"><img src="../images/gallery.png"></a>';
以下是我在 Logcat 中获得的信息:
File locaton is: /storage/emulated/0/Pictures/Screenshots/Screenshot_2016-05-13-21-56-20.png
upload content://com.android.providers.media.documents/document/image%3A55766 to http://server.net/project/php/uploads.php
fileKey: file
fileName: image%3A55766
mimeType: image/jpeg
params: {}
trustEveryone: false
chunkedMode: true
headers: null
objectId: 1
httpMethod: POST
Content Length: 259650
【问题讨论】:
标签: javascript android file cordova