在客户端从base64制作图片 [英] Make picture from base64 on client-side

查看:152
本文介绍了在客户端从base64制作图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过使用HttpRequest.request从base64字符串将图片发送到服务器?

How to make a picture from a base64-string to send it to server by using HttpRequest.request?

例如,我有以下base64字符串:

For example, I have the following base64-string:

' data:image / jpeg; base64 ,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCEAAVNQI12P4 // 8 / w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg =='

'data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='

而不是发送它我想发布一个jpeg到服务器?是否可以?

Instead of sending it I would like to post a jpeg to server? Is it possible?

推荐答案

将Base64转换为字节

如何本地转换字符串 - > base64和base64 - >字符串

Convert Base64 to bytes
How to native convert string -> base64 and base64 -> string

以二进制形式上传图片

Dart如何上传图片

编辑

(这是服务器部分,我必须查找客户端部分)

Upload binary as image
Dart how to upload image
EDIT
(this is the server part, I have to look for the client part)

客户端代码:

  var request = new HttpRequest()
    ..open("POST", 'http://yourdomain.com/yourservice')
    ..overrideMimeType("image/your-imagetype") // might be that this doesn't work than use the next line
    ..setRequestHeader("Content-Type", "image/your-imagetype")
    ..onProgress.listen((e) => ...);

  request
    ..onReadyStateChange.listen((e) => ...)
    ..onLoad.listen((e) => ...)
    ..send(yourBinaryDataAsUint8List);

转换为图片

我认为你需要创建一个数据URL,例如如何在Dart中上传文件?

,然后使用创建的dataUrl as src in code like such here here 如何在Dart中加载图片

另请参见 Base64 png数据到html5画布作为@DanFromGermany在他的问题的评论中提到。

Convert to image:
I think you need to create a dataURL like show here How to upload a file in Dart?
and then use the created dataUrl as src in code like shown here How to load an image in Dart
see also Base64 png data to html5 canvas as @DanFromGermany mentioned in his comment on the question.

可能需要将List转换为Uint8List。

如果需要更多信息,请添加注释。

It may be necessary to convert List to Uint8List in between.
Please add a comment if you need more information.

这篇关于在客户端从base64制作图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆