Commit 9b4a572b authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: Actually upload the file

parent 7ba4745a
import * as UrlTemplate from 'url-template';
import * as QueryString from 'query-string';
import { axiosBackend } from 'utilities/requestUtils';
import FolderDetails from 'model/repository/FolderDetails';
......@@ -272,23 +271,24 @@ class FileRepositoryService {
* @param file file
* @param metadata metadata
*/
public static uploadFile(path: string, file: File, metadata?: string): Promise<RepositoryFile> {
public static uploadFile(path: string, file: File, metadata?: RepositoryFile): Promise<RepositoryFile> {
const qs = QueryString.stringify({
metadata: metadata || undefined,
}, {});
const apiUrl = URL_UPLOAD_FILE.expand({}) + path + (qs ? `?${qs}` : '');
const apiUrl = URL_UPLOAD_FILE.expand({}) + path;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
const data = new FormData();
data.append('file', file);
data.append('metadata', JSON.stringify(metadata));
// data.append('metadata', new Blob([ JSON.stringify(metadata) ], { type : 'application/json' }));
const content = { data };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
headers: { 'Content-Type': 'multipart/form-data' },
...content,
}).then(({ data }) => data as RepositoryFile);
}
}
export default FileRepositoryService;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment