English 中文(简体)
阅读AAsDataURL 后,PNG的基地64号楼落成无效,但JPG/JPEG则不然。
原标题:readAsDataURL returns an invalid Base64 string for PNG, but not for JPG/JPEG

Running a React Native app, and trying to solve this issue. The b64 is sent to a an API and stored in db as blob, I know it s not best practice, but this isn t an app of any scale, just a simple student project.


const file = await DocumentPicker.getDocumentAsync({
        type: "image/*",
        copyToCacheDirectory: true,
    });

用于流动:

const uri = await fetch(file.uri);
const blob = await uri.blob();
const res = await new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(blob);
      reader.onloadend = () => resolve(reader.result);
      reader.onerror = (error) => reject(error);
}).then((result) => {
   return result;
}); 
base64 = res as string;

仅供网站使用。 从那时起,就座。

然而,在这两种情况下,b64 p不正确,但对 j和 j来说是正确的。 这个问题是众所周知的,还是我刚刚失去了一些特殊警卫,我需要拿起甲型六氯环己烷的价值吗?

FYI 采用权宜法

Edit, example of the b64 which produced for png:

https://controlc.com/f9073658 -b64 too long for SO
问题回答

Base64 is just encoding bytes using 64 ASCII symbols. I am not sure I got what is wrong with PNG but if you want you can use standard Image component from React Native like this:

// include at least width and height!
<Image
  style={{
    width: 51,
    height: 51,
    resizeMode:  contain 
  }}
  source={{
    uri:  data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg== 
  }}
/>

我也面临这一问题。 就我而言,问题在于,我在背后使用的基64发动机是无pad的,因此,任何基64与婚后特性(=)相呼应的发动机都造成了脱节错误。

当然,解决办法是将基64发动机改为包括dding在内的发动机。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签