curlconverter / curlconverter

Transpile curl commands into Python, JavaScript and 27 other languages
https://curlconverter.com
MIT License
7.17k stars 867 forks source link

If curl with formData has already produced double quotes, then create them twice. #590

Closed jasanishubh123 closed 8 months ago

jasanishubh123 commented 8 months ago
image

Check this curl --location 'https://api.escuelajs.co/api/v1/files/upload' \ --form 'file=@"/Users/shubhamjasani/Desktop/ss.png"'

I got this output

import axios from 'axios';
import FormData from 'form-data';
import * as fs from 'fs';

const form = new FormData();
 // twice quoted which throws error.
form.append('file', fs.readFileSync('"/Users/shubhamjasani/Desktop/ss.png"'), '"/Users/shubhamjasani/Desktop/ss.png"');

const response = await axios.post(
  'https://api.escuelajs.co/api/v1/files/upload',
  form,
  {
    headers: {
      ...form.getHeaders()
    }
  }
);
verhovsky commented 8 months ago

Duplicate of #217