amis icon indicating copy to clipboard operation
amis copied to clipboard

jdk的封装的fetcher,上传图片报错,

Open jackHuang-123 opened this issue 3 years ago • 4 comments

实现场景:

请简单描述你想要实现的原始场景,例如:我想要实现xxx的功能... 我想要fetcher能够实现上传图片的效果

存在的问题:

请简单描述你现在遇到的不符合预期的问题... 上传失败

当前方案:

请粘贴你当前方案的完整 amis schema 代码...

json文件内容{ "type": "input-image", "label": "图片集", "name": "album", "autoUpload": true, "proxy": true, "uploadType": "fileReceptor", "imageClassName": "r w-full", "id": "u:aaad6b6d58f9", "accept": ".jpeg, .jpg, .png, .gif", "multiple": true, "hideUploadButton": false, "fixedSize": false, "receiver": { "url": "$api_domain/api/cms/information/upload2?url\u003dalbum", "method": "post", "messages": {}, "dataType": "form-data" } },


封装的fetcher  {
                fetcher: function (params) {
                    var data = params.data;
                    var body =params.body
                    var method = params.method;
                    var query  =params.query
                    var url = params.url;
                  
                    return new Promise(function (resolve, reject) {
                        fetch(url, {
                            method: method,
                            body:data,
                            headers: new Headers({
                               "Content-Type": "application/json"
                            }),
                        })
                            .then(function (res) {
                                // console.log(123, res);
                                return res.json();
                            })
                            .then(function (response) {
                                  console.log(1111,response);
                                resolve({
                                    data: response,
                                });
                            });
                    });
                },
            }
code here...

jackHuang-123 avatar May 19 '23 09:05 jackHuang-123

👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

github-actions[bot] avatar May 19 '23 09:05 github-actions[bot]

image image

jackHuang-123 avatar May 19 '23 09:05 jackHuang-123

headers: new Headers({
   "Content-Type": "application/json"
}),

如果 data 是 blob 不要去设置 header

2betop avatar May 19 '23 13:05 2betop

感谢,问题已解决

jackHuang-123 avatar May 24 '23 08:05 jackHuang-123