What URI format does ImageStore.getBase64ForTag expect?

会有一股神秘感。 提交于 2019-12-11 08:41:14

问题


Suppose I have an Image, for example from the Image Picker, that looks like this:

{
  "height": 2848,
  "origURL": "assets-library://asset/asset.JPG?id=B84E8479-475C-4727-A4A4-B77AA9980897&ext=JPG",
  "cancelled": false,
  "width": 4288,
  "fileSize": 342120,
  "isVertical": false,
  "uri": "file:///Users/sepp/Library/Developer/CoreSimulator/Devices/998C81E0-5CC6-4A3E-90C2-A7C43060220C/data/Containers/Data/Application/53F9F372-37DD-4CD2-B5E2-0D984A064686/Library/Caches/%2540anonymous%252Fcleanguide-c5413b44-e71a-4958-80a6-25b9c9e5d7a5/ImagePicker/A1D3644A-516E-4D7C-911C-2AC120B229BB.jpg"
}

Looking at the docs for React Natives ImageStore (https://facebook.github.io/react-native/docs/imagestore.html), one would assume that passing the URI of that Image to ImageStore.getBase64ForTag should return the base64 for that Image.

Instead it produces an error Invalid imageTag: file:///Users/sepp/Library[…] (shortened for readability).

So my question is: What kind of URIs does ImageStore.getBase64ForTag expect?


回答1:


This post on the React Native issue tracker has the answer:

To use ImageStore.getBase64ForTag, you first have to get your image into the ImageStore, which can only be done by using the ImageEditor.cropImage function first.

That may seem cumbersome, and it is, but that's because we generally don't encourage converting images to base64 data. If you can explain what you're trying to do, there might be a better approach, or we might be able to create a better API for it.



来源:https://stackoverflow.com/questions/44687594/what-uri-format-does-imagestore-getbase64fortag-expect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!