2015-01-09 73 views
1

我正在複製從s3上的.ipa文件中提取的圖像。該文件正在移動正確,但是當我嘗試在瀏覽器中查看它時,它在Google Chrome瀏覽器中似乎已損壞。如果我直接將文件下載到我的機器並打開它看起來非常好。它也在Safari中呈現。s3上存儲的文件不在瀏覽器中呈現

Dir.mktmpdir do |dir| 
    Zip::File.open(tmp_ipa) do |zip_file| 
    # Find Icon File 
    icon = zip_file.find do |entry| 
    entry.name.include? '[email protected]' 
    end 
    icon.extract(File.join(dir, 'AppIcon.png')) 
    s3_icon = bucket.objects[icon_dest] 
    s3_icon.write(Pathname.new(File.join(dir, 'AppIcon.png'))) 
    icon_url = s3_icon.public_url.to_s 
    end 
end 
+0

嘗試在Chrome中打開本地文件,它是否呈現? – 2015-01-09 22:06:34

+0

@ AlexanderO'Mara它不是 – 2015-01-09 22:15:49

回答

2

這幾乎可以肯定是因爲Apple uses a non-standard proprietary extension of the PNG file format for the PNG files in an iPhone APParchived link),比如你說的.ipa是從中提取的。

它在Safari中工作的原因是因爲Safari使用OS的圖像解碼庫,它支持這種非標準格式。

are some conversion scripts out there,即work with varying success

+0

謝謝,我已經使用了具有'IpaReader :: PngFile.normalize_png(data)'功能的ipa_reader gem。我只需要弄清楚如何使用它。 – 2015-01-09 22:56:54

3

最有可能的問題是,你沒有設置Content-Typeimage/png當你上傳你的圖片S3。試試這個命令行:

curl -i http://your-bucket.s3.amazonaws.com/path/to/AppIcon.png 

什麼是Content-Type頭?如果不是image/png,請在上傳時進行設置。

+0

內容類型是'Content-Type:application/xml' – 2015-01-09 22:18:09

+0

像Chrome這樣的瀏覽器只會嘗試渲染一個png文件,如果Content-Type是'image/png' 。 – Asaph 2015-01-09 22:19:43

+0

這可能是你的修復是這個答案和[@ Alexanderomara的答案](http://stackoverflow.com/a/27870133/166339) – Asaph 2015-01-09 22:21:28

相關問題