GithubHelp home page GithubHelp logo

hhy5277 / reactnative-fileupload Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hapenly/reactnative-fileupload

0.0 2.0 0.0 2.15 MB

ReactNative 实现的文件上传功能。支持任意文件上传,欢迎Star! !

License: MIT License

JavaScript 55.65% Python 10.15% Java 8.31% Objective-C 25.89%

reactnative-fileupload's Introduction

欢迎大家加群讨论

点击链接加入群ReactNative-解决问题交流群 :644124441

点击链接加入群ReactNative技术交流群2 :687663534

ReactNative-FileUpload

已经实现文件上传功能。以下是关键代码,按照我的写法实现文件上传是没有问题的。有问题可以开个issues。给个Star,感谢!

欢迎大家加群讨论 点击链接加入群ReactNative-解决问题交流群 :644124441

演示

服务器文件

//**************文件上传**************
    uploadImage(imgAry){
        console.log('imgAry', imgAry);
        let formData = new FormData();       //因为需要上传多张图片,所以需要遍历数组,把图片的路径数组放入formData中
        for(var i = 0;i<imgAry.length;i++){
//截取获取文件名
            var a=imgAry[i].uri;
            var arr = a.split('/');
// 获取文件名end
//      判断文件的类型(视频-图片等)end
            let file = {uri: imgAry[i], type: imgAry[i].mime, name: arr[arr.length-1]};   //这里的key(uri和type和name)不能改变,
            formData.append("file", file);   //这里的files就是后台需要的key
            //这里的files就是后台需要的key
        }
        console.log('formData', formData);
        console.log('uri', imgAry[0].uri);
        var request = {
            imgAry,
        };
        console.log('request', request);
        fetch('http://'+yourServerIP+'/api/resources',{
            method:'POST',
            headers:{
                'Content-Type':'multipart/form-data',
            },
            body:formData,
        })
        // .then((response) => response.json())
            .then((responseData)=>{
            alert('文件上传成功!');
        console.log('responseData=',responseData);

    })
    .catch((error)=>{console.error('error=',error)});
    },

reactnative-fileupload's People

Contributors

hapenly avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.