Azure的BLOB放 - 图像损坏 [英] Azure blob put - image corrupt

查看:505
本文介绍了Azure的BLOB放 - 图像损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Azure存储BLOB把一个项目就可以了。
它正常工作与PDF,MP3,但是,当我上载的图片文件(或TXT文件),该文件已经修改。

I'm trying to use the azure storage blob to put an item on it. It works fine with PDF, MP3 but, when I upload an IMAGE file (or TXT file) the file has changed.

当我下载PDF格式或MP3,文件可读。但对于图像,它说,它是腐败...
然而,TXT文件可读,但内容被包围在 webkitfromboundary

When I download the pdf or the mp3, the file is readable. But for the image, it says that it's corrupt ... However the TXT file is readable but the content is surrounded by the webkitfromboundary

我认为这就是为什么图像不工作的原因...

I thinks this is the reason why image don't work...

例:

TXT文件你好字仅 - >

------WebKitFormBoundary3rxc8zHbnz4expeP
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

hello word
------WebKitFormBoundary3rxc8zHbnz4expeP--

所以我想这就是为什么图像不工作的原因

So I guess this is the reason why images don't work

所以这是我上传(从 angularJS )---我使用的 https://github.com/danialfarid/ng-file-upload

so this is my upload (from angularJS) --- I Use https://github.com/danialfarid/ng-file-upload

Upload.upload
  url: url
  method: 'PUT'
  headers: head
  file: file
  .success (data, status, headers, config) ->
    console.log("SUCCES!!!")

头的值 - (一个文本文件)

value of head - ( for an text file)

{"x-ms-version":"2014-02-14","x-ms-blob-type":"BlockBlob","x-ms-date":"2015-11-06 10:02:24 GMT","Authorization":"SharedKey generate_key","Content-Type":"text/plain"}

ofcourse,当时这是一个图像内容类型的变化(需要的 file.type

如果它可以帮助,这是在请求头从网络页面 - >

If it can help, this is the request headers from the network page ->

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:fr,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:214
Content-Type:application/json;charset=utf-8
Host:myaccount.blob.core.windows.net
Origin:http://localhost:9000
Referer:http://localhost:9000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36

请求负载 - >

------WebKitFormBoundary3rxc8zHbnz4expeP
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain


------WebKitFormBoundary3rxc8zHbnz4expeP--


因此​​,任何人有一个想法?


So, anyone has an idea ?

推荐答案

该anwser是,内容类型在HTTP请求发送从来都不是好的类型。

The anwser was that the Content-Type sent in the http request was never the good type.

这是因为

Upload.upload

不允许你改变它。

doesn't allow you to change it.

BUT 您可以使用相同的库的 HTTP 方法,并且它会工作那样:

BUT you can use the http method of the same library, and it'll work like that :

  Upload.http
    url: uploadInfo.url
    method: 'PUT'
    headers: {
    "Content-Type": file.type
    [other headers ...]
  }
  data: file

和你去那里!它的工作原理!

and there you go ! it works !

这篇关于Azure的BLOB放 - 图像损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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