Skip to content

Commit 447ec67

Browse files
committed
UI: File upload: take chosen subdirectory into account
closes #255
1 parent b56c491 commit 447ec67

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

frontend/component/fileupload.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ interface UploadProgress {
3030
interface FileUploadAreaProps {
3131
collectionId: string;
3232
collectionRevision: string;
33+
/** `` if should upload files to root. `documentation/topic` (without trailing slash) if to nested subdir */
34+
pathForUploadedFiles: string;
3335
}
3436

3537
interface FileUploadAreaState {
@@ -150,11 +152,14 @@ export class FileUploadArea extends React.Component<FileUploadAreaProps, FileUpl
150152
}
151153

152154
private async uploadOneFile(file: File): Promise<File2> {
155+
const pathPrefix =
156+
this.props.pathForUploadedFiles.length > 0 ? this.props.pathForUploadedFiles + '/' : '';
157+
const fileBasename = file.name; // spec says: "without path information"
158+
153159
const uploadEndpoint = makeQueryParams(uploadFileUrl(this.props.collectionId), {
154160
mtime: file.lastModified.toString(),
155-
filename: file.name, // spec says: "without path information"
161+
filename: pathPrefix + fileBasename,
156162
});
157-
158163
// TODO: upload progress
159164
// fetch() doesn't provide an API for it so it was not easy :(
160165

frontend/pages/CollectionPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ export default class CollectionPage extends React.Component<
204204
}
205205
});
206206

207+
const pathForUploadedFiles = this.props.pathBase64 ? atob(this.props.pathBase64) : '';
208+
207209
return (
208210
<div>
209211
<SensitivityHeadsUp />
@@ -333,6 +335,7 @@ export default class CollectionPage extends React.Component<
333335
</div>
334336
}>
335337
<FileUploadArea
338+
pathForUploadedFiles={pathForUploadedFiles}
336339
collectionId={this.props.id}
337340
collectionRevision={coll.Head}
338341
/>

0 commit comments

Comments
 (0)