Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert the picture of Mini Program into base64

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to convert the picture of Mini Program into base64". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to convert the picture of Mini Program into base64" can help you solve your doubts.

Currently, it is not possible to convert Mini Program pictures or local files into base64. The following is a detailed analysis:

WeChat Mini Programs wx.uploadfile, using the PHP interface to convert local pictures into base64 streams.

Paste-and-copy wx.uploadfile solutions are everywhere online, but there is no specific code yet:

It is specially presented to those who need it:

Code:

Case 'imgBufferToBase64':

$data=''

File_put_contents ("1.txt", var_export ($_ FILES,true). "\ r\ n", FILE_APPEND)

If (! empty ($_ FILES ['upload'] [' tmp_name'])) {

If (empty ($_ FILES ['upload'] [' type'])) {

IO::Debug ('invalid file type')

}

If (! in_array ($_ FILES ['upload'] [' type'], array (

'image/gif'

'image/pjpeg'

'image/jpeg'

'image/x-png'

'image/png'

'image/bmp'

)) {

IO::Debug ($_ FILES ['upload'] [' type'].' Illegal file type')

}

$data=file_get_contents ($_ FILES ['upload'] [' tmp_name'])

File_put_contents ("1.txt", var_export ($data,true). "\ r\ n", FILE_APPEND)

IO::Debug ('parsed successfully', true,$data)

}

IO::Debug ("resolution failed")

Break

Js Code:

Wx.uploadFile ({

Url: 'https://' + app.globalData.host +' / api/?sign=' + sign

FilePath: tempFilePaths [0]

Name: 'upload'

Header: {

"content-type": "multipart/form-data"

"content-type": "application/x-www-form-urlencoded"

}

FormData: formData

Success: function (res) {var $data = JSON.parse (res.data); if (typeof ($data.data)! = "undefined" & & $data.code) {

Var imgBase64 = _ "data:image/jpeg;base64," + $data.data

}

}

})

After reading this, the article "how to convert Mini Program pictures into base64" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about the articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report