-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-file.js
40 lines (33 loc) · 1.06 KB
/
upload-file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
RESPONSE=$(curl -s -X POST -H "Authorization: Token $REPLICATE_API_TOKEN" https://dreambooth-api-experimental.replicate.com/v1/upload/sample_data_processing_course.jsonl)
curl -X PUT -H "Content-Type: application/jsonl" --upload-file sample_data_processing_course.jsonl "$(jq -r ".upload_url" <<< "$RESPONSE")"
SERVING_URL=$(jq -r ".serving_url" <<< $RESPONSE)
echo $SERVING_URL
*/
import fs from 'fs';
import dotenv from 'dotenv';
import axios from 'axios';
dotenv.config();
const url =
'https://dreambooth-api-experimental.replicate.com/v1/upload/sample_data_processing_course.jsonl';
const file = 'sample_data_processing_course.jsonl';
go();
async function go() {
const response = await axios.post(
url,
{},
{
headers: {
Authorization: `Token ${process.env.REPLICATE_API_TOKEN}`,
},
}
);
const { upload_url, serving_url } = response.data;
const fileStream = fs.createReadStream(file);
await axios.put(upload_url, fileStream, {
headers: {
'Content-Type': 'application/jsonl',
},
});
console.log(serving_url);
}