leancloud / leanengine-node-sdk

LeanEngine Node.js SDK
https://leancloud.cn
MIT License
61 stars 21 forks source link

AV.File not saving base64 #124

Closed johncalvinroberts closed 6 years ago

johncalvinroberts commented 6 years ago

Hi all, having an issue with the leanengine sdk AV.File.save api in node v8.9.1. The URL in the response shows a blank image, and base64 seems to have not been saved to the database.

I'm getting an image's binary png from another restful endpoint, and want to save it as an instance of AV.File. Like so:

function ({data}) {
  const base64data = new Buffer(data.toString(), 'binary').toString('base64')
  const file = new AV.File(`qr_code.png`, {base64: base64data}, 'image/png')
  return file.save()
}

The response from saving to the backend looks like this:

{ "result": { "name": "qr_1.png", "url": "http://ac-tSaB7MBC.clouddn.com/9a12355a3edee6f7af17.png", "metaData": { "owner": "unknown" }, "base64": "", "mime_type": "image/png", "objectId": "5a9d0ffbfe88c21c80c6d5b2" } }

The URL shows a blank image, also base64 in the response is blank. I've done the same thing with base64 in the frontend with leancloud-storage package and had no problem. Thanks in advance!! And thanks for an awesome product in general~~~

leeyeh commented 6 years ago

Can you please provide a base64data for me to reproduce this issue?

Also, in Node.js, AV.File accepts a Buffer or a Stream as the data param. So there is no need to encode the data to base64 string.

johncalvinroberts commented 6 years ago

@leeyeh Thanks for your response. I tried sending just the buffer as well, also no luck. This is the binary I'm working with, data namespace from this endpoint:

https://api.weixin.qq.com/wxa/getwxacode?access_token=7_iu1IJ65yK5zZy52rgosCYZVc-zzmHnjsuWPUra7DpJTKS_tIYYZ3szFixIUVv_Y3k6kD1pAm6LhxeHhtfq2rs6iulA3Eh-PUT5Ixg3J5sxTsVGstAi-mOtVNeV8NZGjAEACOV

EDIT: Sorry, left out some details. POST to this ^^ url, with this body: { "path": "/pages/animal-profile?animal=5a9ba96afe88c21c80bf62f4" }

EDIT2: Changed access token, it expired

leeyeh commented 6 years ago

We have a tested sample(w/ axios) for such use case: https://forum.leancloud.cn/t/topic/14469/4?u=leeyeh

And a request version: https://forum.leancloud.cn/t/topic/14469/18?u=leeyeh

johncalvinroberts commented 6 years ago

Ah I see, have to specify response type. It works now 😄😄😄

Thanks! 😁

leeyeh commented 6 years ago

Glad to help. 😆