Cordova文件传输:上传到aws s3后无法查看图像 [英] Cordova file transfer: Cannot view image after upload to aws s3
问题描述
我使用cordova文件传输将图片上传到我的s3存储桶。
我管理上传文件没有任何错误,甚至可视为文件s3。
但是当我尝试从s3下载图片时,我无法查看它(图片已损坏)
当执行 file image.png
im得到的结果是一个数据文件而不是一个图像..
这里是上传的代码: / p>
let transfer = new Transfer();
options = {
headers:{
'Content-type':'image / jpg',
},
httpMethod:'PUT',
chunkedMode:false
};
console.log(URL,,url)
return transfer.upload(fileUrl,url,options,true)
我尝试使用或不使用
encodeURI
方法,有或没有chunkmode
没有什么似乎工作。任何想法?
这个代码使用离子本地库,但我也尝试去海峡到
FileTransfer
仍然没有工作
我也使用从我的网络服务器上传的一个单独的URL上传
这里是我用于本机FileTransfer
对象的代码var options = new FileUploadOptions();
options.headers = {'Content-type':'image / jpg'}
options.httpMethod ='PUT';
options.chunkedMode = false;
options.mimeType ='image / jpg';
var ft = new FileTransfer();
ft.upload(fileURL,url,onSuccess,onFail,options,true);
解决方案问题是
内容类型
头
Content-Type
Content-type 解决了问题Im working with cordova file transfer to upload images to my s3 bucket.
I mange to upload the file without any errors, and its even visable as a file in s3.
But when I try to download the image from s3, I can't view it (image is corrupted) when doing
file image.png
im getting a result that it is a data file and not an image..here is the upload code:
let transfer = new Transfer(); options = { headers: { 'Content-type': 'image/jpg', }, httpMethod: 'PUT', chunkedMode: false }; console.log("URL, ", url) return transfer.upload(fileUrl, url, options, true)
I tried with or without
encodeURI
method, with or withoutchunkmode
nothing seems to work. any ideas?Ps this code uses ionic native library but i also tried go strait to the
FileTransfer
object and it still didnt workIm also using a singed url that im getting from my web server pre uploading
UPDATE: here is the code that i used with the native
FileTransfer
objectvar options = new FileUploadOptions(); options.headers = { 'Content-type': 'image/jpg' } options.httpMethod = 'PUT'; options.chunkedMode = false; options.mimeType = 'image/jpg'; var ft = new FileTransfer(); ft.upload(fileURL, url, onSuccess, onFail, options, true);
解决方案The problem was with the
Content-type
header
Content-Type
instead ofContent-type
solved the problem这篇关于Cordova文件传输:上传到aws s3后无法查看图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!