Sending images to external endpoints

Is there a recommended way to send a database image via post to an external endpoint?

I am creating a backend function that takes an image url (from a custom form in a page) and sends it as a binary file in a POST.

I already have tried with npm packages as got, axios, etc. The enpoint works fine since I tested it with postman.

thanks

Hello. Can you share your code and also what format the image url looks like when you try to send it?

Are there any errors?

Thank you Amanda. I think I found a solution (will test and get back to you):

export function uploadImage ( urlImage ) {

**const**  url  =  [endpointURL] 

**return**  **get** ( urlImage , {  responseType :  'arraybuffer'  }). then (( response ) => { 

    **const**  buffer  =  Buffer . **from** ( response . data ,  "utf-8" ) 

    **const**  headers  = { 
        "Content-type" :  "application/octet-stream" 
    }; 
 
    **const**  request  = { 
        headers :  headers , 
        method :  'POST' , 
        body :  buffer 
    }; 

    **return**  fetch ( url ,  request ). then (( httpResponse ) => { 

            **return**  httpResponse . json (). then (( body ) => { 
                **return**  response ; 
            }) 
        }) 
        . **catch** (( error ) => { 
            console . log ( error ); 
            **return**  error ; 

        }); 

        
}); 

}

1 Like

@juancamilorodriguezr Yes, please let us know how it goes!