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 take photos or select pictures from albums to upload in WeChat Mini Programs

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to take photos or select pictures from photo albums in WeChat Mini Programs". The explanation in the article is simple and clear and easy to learn and understand. let's study and learn "how to take photos or select pictures from photo albums in WeChat Mini Programs".

Find a problem

The boss wanted me to download xls files. I thought about it: I don't seem to know how to do it.

But a page we wrote earlier has a function to download xls, so I will CV Dafa, heh.

When I clicked the download button, the console went red. I thought MMP.

The same code is not good, which can be downloaded, and I deteriorated after CV?

TypeError: Failed to execute 'createObjectURL' on' URL': Overload resolution failed.

I looked at the network request, the boss said that the data transmitted is fine, maybe the data is too large?

I have read a lot of blogs, and their solution is to Blob the transmitted data, so let's give it a try.

Let blob = new Blob ([res], {type: 'application/vnd.ms-excel'}) const url = window.URL.createObjectURL (res)

Alas? It's ready to download! But the data in the table is garbled.

I can't think about it! They all came to see the blog of a friend of Digg. What he did was to add responseType: 'blob' to the request header.

Finally, I succeeded in solving the problem, woo-hoo.

Summary

When downloading big data files, add responseType: 'blob', to the request header to solve the problem of downloading and internal chaos code in the file.

The code is attached below

/ / File download-label method downloads download (row.logUserId). Then (res = > {if (! res) {return} / / the blob processing here can be done or not, I tried it. You can download without blob and without garbled let blob = new Blob ([res], {type: 'application/vnd.ms-excel'}) const url = window.URL.createObjectURL (blob) const link = document.createElement (' a') link.style.display = 'none' link.href = url / / download attribute defines the address of the download link instead of the jump path link.setAttribute (' download' Row.reportExcelLog.fileName+'.xls') document.body.appendChild (link) link.click () window.URL.revokeObjectURL (link.href) / release url document.body.removeChild (link) / / release tag}) / / request export function download (logUserId) {return request ({url: prefix +'/ download/by/log/user/id', method: 'post', data: {logUserId} / / this step is very important responseType: 'blob'})} Thank you for your reading The above is the content of "how to take photos or select pictures from albums in WeChat Mini Programs". After the study of this article, I believe you have a deeper understanding of the problem of how to take photos or select pictures from albums to upload in WeChat Mini Programs. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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