Cordova文件传输:上传到aws s3后无法查看图像 [英] Cordova file transfer: Cannot view image after upload to aws s3

查看:589
本文介绍了Cordova文件传输:上传到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 without chunkmode 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 work

Im 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 object

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);

解决方案

The problem was with the Content-type header

Content-Type instead of Content-type solved the problem

这篇关于Cordova文件传输:上传到aws s3后无法查看图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆