40 lines
919 B
Markdown
40 lines
919 B
Markdown
curl relation
|
|
|
|
- `curl -F "reqtype=fileupload" -F "userhash=####" -F "fileToUpload=@cutie.png" https://catbox.moe/user/api.php`
|
|
Converting to node-fetch
|
|
```js
|
|
import fetch, { FormData, fileFromSync } from 'node-fetch';
|
|
|
|
const form = new FormData();
|
|
form.append('reqtype', 'fileupload');
|
|
form.append('userhash', '####');
|
|
form.append('fileToUpload', fileFromSync('cutie.png'));
|
|
|
|
fetch('https://catbox.moe/user/api.php', {
|
|
method: 'POST',
|
|
body: form
|
|
});
|
|
```
|
|
|
|
Converting to axios
|
|
```js
|
|
import axios from 'axios';
|
|
import FormData from 'form-data';
|
|
import * as fs from 'fs';
|
|
|
|
const form = new FormData();
|
|
form.append('reqtype', 'fileupload');
|
|
form.append('userhash', '####');
|
|
form.append('fileToUpload', fs.readFileSync('cutie.png'), 'cutie.png');
|
|
|
|
const response = await axios.post(
|
|
'https://catbox.moe/user/api.php',
|
|
form,
|
|
{
|
|
headers: {
|
|
...form.getHeaders()
|
|
}
|
|
}
|
|
);
|
|
```
|
|
|