dsuvs66406 2012-05-27 18:03
浏览 100
已采纳

golang:通过电子邮件发送存储为Google Appengine blobstore blob的图像

I'm trying to read a JPEG file stored in the GAE blobstore back into a byte array using the following code:

info,_  := blobstore.Stat(context,appengine.BlobKey(request.FormValue("blobkey")))
image   := make([]byte,info.Size)
reader  := blobstore.NewReader(context,appengine.BlobKey(request.FormValue("blobkey")))
n,nerr  := reader.Read(image)

The image is stored correctly i.e. it can be served using blobstore.Send(...).

And the above code sort of works (in that it does read back the blob data) but it converts any 0x0a byte into a 0x0d 0x0a pair (i.e. LF into CR LF).

Is there a way in Go to work around this behaviour (without writing a filter to convert 0x0d0a back to 0x0a) ?

EDIT:

It turns out the problem is not with Blobstore.Reader at all, but with the attachment encoding in mail.py on the dev appserver.

  • 写回答

1条回答 默认 最新

  • dongshuofu0039 2012-05-29 19:19
    关注

    The mail attachment handling on the dev appserver does not correctly encode image data. If the attachment data is known to be binary, a partial workaround is to add the line:

    encoders.encode_base64(mime_attachment)
    

    after the line

    mime_attachment.set_payload(attachment.data())
    

    in the file

    google/appengine/api/mail.py

    Using a MIMEImage attachment for an image content type would be a better solution but causes a 'LazyImporter object is not callable' error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度