[Vuejs]-How to send a url in form-data as a file using js or axios

0👍

Try opening the file and then encoding it.. something like this..

 function getPdf(){
        // read text from URL location
        var request = new XMLHttpRequest();
        request.open('GET', 'https://storage.cloudconvert.com/xxxxx.pdf', true);
        request.send(null);
        request.onreadystatechange = function () {
            if (request.readyState === 4 && request.status === 200) {
                var type = request.getResponseHeader('Content-Type');
                if (type.indexOf("pdf") !== 1) {
                    return request.responseText;
                }
            }
        }
    }
// Encode the String
    var pdf = btoa(getPdf()); 
    
    
    var data = new FormData();
           
            data.append('name','file')
            data.append('filename', 'amjad');
            data.append('file', pdf);
            data.append('saved', 'true');
            data.append('type', 'pdf');
            axios.post('myapiurl',data, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                },
    
            }).then(res => {
                console.log(res);
            })

Leave a comment