const axios = require('axios')
const FormData = require('form-data')
const crypto = require('crypto')
// const fs = require('fs')
const get_image(url) => {
return axios.get(url, {
responseType: 'arraybuffer',
headers: {
'Content-Type': 'image/jpg'
},
params: {aspect: 0.8}
)
}
const transfer_image = (url, image) => {
const form = new FormData()
form.append('file', image, {contentType: 'image/jpg', filename: `${crypto.randomUUID()}.jpg`}, knownLength: image.length)
# form.append('file', fs.readFileSync(fpath_image), {contentType: 'image/jpg', filename: fpath_image})
return axios.post(url, form, {
headers: {
...form.getHeaders(),
},
maxContentLength: Infinity,
maxBodyLength: Infinity
})
}
async function main(url_image, url_post){
const res0 = await get_image(url_image)
const res1 = await transfer_image(url_post, res0.data)
}