<tfoot id='dvoEZ'></tfoot>
      • <bdo id='dvoEZ'></bdo><ul id='dvoEZ'></ul>

    1. <legend id='dvoEZ'><style id='dvoEZ'><dir id='dvoEZ'><q id='dvoEZ'></q></dir></style></legend>
      <i id='dvoEZ'><tr id='dvoEZ'><dt id='dvoEZ'><q id='dvoEZ'><span id='dvoEZ'><b id='dvoEZ'><form id='dvoEZ'><ins id='dvoEZ'></ins><ul id='dvoEZ'></ul><sub id='dvoEZ'></sub></form><legend id='dvoEZ'></legend><bdo id='dvoEZ'><pre id='dvoEZ'><center id='dvoEZ'></center></pre></bdo></b><th id='dvoEZ'></th></span></q></dt></tr></i><div id='dvoEZ'><tfoot id='dvoEZ'></tfoot><dl id='dvoEZ'><fieldset id='dvoEZ'></fieldset></dl></div>

      <small id='dvoEZ'></small><noframes id='dvoEZ'>

        React Native 上传图片失败

        React Native Failed Upload Image(React Native 上传图片失败)
        <tfoot id='Tiz2Y'></tfoot>
        <legend id='Tiz2Y'><style id='Tiz2Y'><dir id='Tiz2Y'><q id='Tiz2Y'></q></dir></style></legend>

          1. <i id='Tiz2Y'><tr id='Tiz2Y'><dt id='Tiz2Y'><q id='Tiz2Y'><span id='Tiz2Y'><b id='Tiz2Y'><form id='Tiz2Y'><ins id='Tiz2Y'></ins><ul id='Tiz2Y'></ul><sub id='Tiz2Y'></sub></form><legend id='Tiz2Y'></legend><bdo id='Tiz2Y'><pre id='Tiz2Y'><center id='Tiz2Y'></center></pre></bdo></b><th id='Tiz2Y'></th></span></q></dt></tr></i><div id='Tiz2Y'><tfoot id='Tiz2Y'></tfoot><dl id='Tiz2Y'><fieldset id='Tiz2Y'></fieldset></dl></div>
                <bdo id='Tiz2Y'></bdo><ul id='Tiz2Y'></ul>
                  <tbody id='Tiz2Y'></tbody>

                <small id='Tiz2Y'></small><noframes id='Tiz2Y'>

                  本文介绍了React Native 上传图片失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  过去两天我一直在努力破解使用 React Native 上传到 MongoDB 的文件/图像.我从字面上阅读了所有相关的论坛,但没有运气.我阅读了几个论坛,他们给出了一个示例,但我没有成功.这是我编写的示例代码.

                  I am struggling from the past 2 days to crack the file/image upload with React Native to MongoDB. I literally read all the related forums but there is no luck. I read couple of forums and they gave a sample example but I wasn't succeeded. Here are the sample codes that I wrote.

                  const { uri } = await this.camera.takePictureAsync(options);
                  
                  let formData = new FormData();
                  formData.append('file', {
                    uri: uri.replace("file:///", ""),
                    type:'image/jpg', name:'userProfile.jpg',
                  });
                  
                  const rawResponse = await fetch('http://192.168.1.5:9000/api/contrats/upload', {
                    method: 'POST',
                    body: formData,
                    headers: {
                      Accept: 'application/json',
                      'Content-Type': 'multipart/form-data; charset=utf-8',
                      },
                  });
                  
                  
                  const content = await rawResponse.json();
                  
                  console.log(content);

                  var storage = multer.diskStorage({
                    destination: (req, file, cb) => {
                      
                   
                      cb(null, __basedir + '/resources/static/assets/uploads');
                      
                    },
                    filename: (req, file1, cb) => {
                      console.log("file : ", file);
                      let name = file.originalname || file.name;
                      let extension = name.substr((~-name.lastIndexOf(".") >>> 0) + 2);
                      let filename = generateId() +"."+ extension;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       nsion;
                      cb(null, filename)
                  
                    },
                  
                  
                  });
                  
                  var upload = multer({
                    storage: storage,
                    limits: {
                      fileSize: 1024 * 1024 * 5
                    }
                  });

                  推荐答案

                  试试下面的

                        let body = new FormData();
                         let filename = uri.split('/').pop();
                         body.append('file',  {uri:uri, name:filename, type:'image/jpg', });
                         const header = {
                             'Accept': 'application/json',
                             'content-type': 'multipart/form-data',
                           }
                             fetch("http://192.168.1.5:9000/api/contrats/upload", {
                                 method: 'POST',
                                 headers: header,
                                 body:body,
                             }).then(response => response.json())
                              .then(res => console.log(res))
                              .catch(err => console.log("err", err)
                  

                  这篇关于React Native 上传图片失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Gradient Button to background-color blinks on hover(悬停时背景颜色的渐变按钮闪烁)
                  How to make hovering over active button not use hover effect?(如何使悬停在活动按钮上不使用悬停效果?)
                  html javascript show image hover(html javascript 显示图像悬停)
                  How to get css hover values on click?(如何在点击时获得 css 悬停值?)
                  Change background image on link hover(更改链接悬停时的背景图像)
                  Highlight multiple items on hover#39;s condition(突出显示悬停条件下的多个项目)

                1. <tfoot id='TT59V'></tfoot>
                    • <i id='TT59V'><tr id='TT59V'><dt id='TT59V'><q id='TT59V'><span id='TT59V'><b id='TT59V'><form id='TT59V'><ins id='TT59V'></ins><ul id='TT59V'></ul><sub id='TT59V'></sub></form><legend id='TT59V'></legend><bdo id='TT59V'><pre id='TT59V'><center id='TT59V'></center></pre></bdo></b><th id='TT59V'></th></span></q></dt></tr></i><div id='TT59V'><tfoot id='TT59V'></tfoot><dl id='TT59V'><fieldset id='TT59V'></fieldset></dl></div>

                        <tbody id='TT59V'></tbody>
                      <legend id='TT59V'><style id='TT59V'><dir id='TT59V'><q id='TT59V'></q></dir></style></legend>

                      <small id='TT59V'></small><noframes id='TT59V'>

                            <bdo id='TT59V'></bdo><ul id='TT59V'></ul>