[Mini Program] More demand download, preview pdf file

Small programs wx.downloadFile, wx.openDocumentcombined use (2)

It should be taken over in the middle of other projects, so the time interval is a bit awkward, and then continue to fill the hole after the last time.
This time, the demand is a special issue section. Use the large background + slide switch to select, select the small image to slide switch, and the background background panorama will display the corresponding special issue picture. Just look at the picture above: it
write picture description here
's all done! , and then the product asked if it could directly use the pdf online preview (wry smile...), I was confused at the time, because I had never used it, and the applet document was not finished. After that, I honestly continued to brush the document.
The hard work pays off, and I found something good:wx.openDocument

write picture description here

Code:

wx.downloadFile({
      url: 'https://*****.***.work/videos/test2.pdf',
      success: function (res) {
        console.log(res)
        var Path = res.tempFilePath              //返回的文件临时地址,用于后面打开本地预览所用
        wx.openDocument({
          filePath: Path,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      },
      fail:function (res){
        console.log(res)
      }
    })

The first thing that was thrown directly to the server was the pdf provided by the client. The file size was 31MB. I wondered whether it would be very large and whether it would take a long time for the user to download. Sure enough, there was a problem, and the direct fail callback returned to me: write picture description here
Exceeded The maximum size of the file, I went back and checked it again. The local storage file size limit: 10MB; so I changed to a smaller pdf, and the address was successfully returned, and the pdf preview was implemented on the mobile phone. But this size limit, I have no way to solve it, only limit the size of the pdf file, if you want to save it locally for a long time, you need to use it wx.saveFile. The road to filling the pit continues

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325987709&siteId=291194637