Upload a file
POST
/api/v1/files/upload
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");curl_easy_setopt(hnd, CURLOPT_URL, "http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1");
struct curl_slist *headers = NULL;headers = curl_slist_append(headers, "Content-Type: multipart/form-data; boundary=---011000010111000001101001");curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n");
CURLcode ret = curl_easy_perform(hnd);using System.Net.Http.Headers;var client = new HttpClient();var request = new HttpRequestMessage{ Method = HttpMethod.Post, RequestUri = new Uri("http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1"), Content = new MultipartFormDataContent { new StringContent("") { Headers = { ContentType = new MediaTypeHeaderValue("application/octet-stream"), ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "file", FileName = "file", } } }, },};using (var response = await client.SendAsync(request)){ response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); Console.WriteLine(body);}package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close() body, _ := io.ReadAll(res.Body)
fmt.Println(res) fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1")) .header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")) .build();HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.body());OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n");Request request = new Request.Builder() .url("http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1") .post(body) .addHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") .build();
Response response = client.newCall(request).execute();import axios from 'axios';
const form = new FormData();form.append('file', 'file');
const options = { method: 'POST', url: 'http://127.0.0.1:58259/api/v1/files/upload', params: {libraryId: '1', pathId: '1'}, headers: {'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001'}, data: '[form]'};
try { const { data } = await axios.request(options); console.log(data);} catch (error) { console.error(error);}const url = 'http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1';const form = new FormData();form.append('file', 'file');
const options = {method: 'POST'};
options.body = form;
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}val client = OkHttpClient()
val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001")val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")val request = Request.Builder() .url("http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1") .post(body) .addHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") .build()
val response = client.newCall(request).execute()use reqwest;
#[tokio::main]pub async fn main() { let url = "http://127.0.0.1:58259/api/v1/files/upload";
let querystring = [ ("libraryId", "1"), ("pathId", "1"), ];
async fn file_to_part(file_name: &'static str) -> reqwest::multipart::Part { let file = tokio::fs::File::open(file_name).await.unwrap(); let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new()); let body = reqwest::Body::wrap_stream(stream); reqwest::multipart::Part::stream(body) .file_name(file_name) .mime_str("text/plain").unwrap() }
let form = reqwest::multipart::Form::new() .part("file", file_to_part("file").await); let mut headers = reqwest::header::HeaderMap::new();
let client = reqwest::Client::new(); let response = client.post(url) .query(&querystring) .multipart(form) .headers(headers) .send() .await;
let results = response.unwrap() .json::<serde_json::Value>() .await .unwrap();
dbg!(results);}curl --request POST \ --url 'http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1' \ --header 'Content-Type: multipart/form-data' \ --form file=@filewget --quiet \ --method POST \ --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \ --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="file"; filename="file"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n' \ --output-document \ - 'http://127.0.0.1:58259/api/v1/files/upload?libraryId=1&pathId=1'Upload a file to a specific library and path. Requires upload permission or admin.
Parameters
Section titled “ Parameters ”Query Parameters
Section titled “Query Parameters ” libraryId
required
integer format: int64
Library ID
pathId
required
integer format: int64
Path ID
Request Body
Section titled “Request Body ” Media type multipart/form-data
object
file
required
File to upload
string format: binary
Responses
Section titled “ Responses ”File uploaded successfully
Media type */*