微信小程序圖片上傳使用整理(一)

1、微信小程序圖片上傳說明javascript

1.目前微信中不支持FileReader等瀏覽器的IO接口,無法直接讀取或處理文件內容,也就無法使用分段處理上傳等。html

更多分段上傳參考:https://blog.csdn.net/u011127019/article/details/52469563java

2.目前微信上傳接口wx.uploadFile(object) 是一個https post的請求,其中content-type爲multipart/form-data 方式。也就是普通的表單上傳。指定文件路徑,調用接口上傳整個文件。小程序

官方接口詳細文檔:https://developers.weixin.qq.com/miniprogram/dev/api/network-file.html#wxuploadfileobject微信小程序

2、圖片上傳示例1api

1.選擇圖片後,馬上上傳處理瀏覽器

js微信

//選擇圖片
    wx.chooseImage({
      success: function (res) {
        console.info(res);
        //上傳處理
        wx.uploadFile({
          url: 'http://localhost:63588/ashx/upload_form.ashx', //上傳地址
          filePath: res.tempFilePaths[0],//上傳圖片路徑
          success: res => {
            console.info(res);
          }
        })
      },
    })

後臺正常表單方式接收post

/// <summary>
    /// upload_form 的摘要說明
    /// </summary>
    public class upload_form : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var req = context.Request;
            if (req.Files.Count > 0)
            {
                //保存文件
                HttpPostedFile file = req.Files[0];
                file.SaveAs(@"I:\" + file.FileName);
                context.Response.ContentType = "text/plain";
                context.Response.Write("文件接收成功");
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

 

更多:url

小程序如何刪除或隱藏頭部導航欄,實現全屏

 微信小程序富文本圖片處理二

微信小程序騰訊視頻插件使用整理

相關文章
相關標籤/搜索