-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Multipart Form Data file uploads (#1130)
* Add multipart form files upload support * clean up * Fixed electron files browser for Multipart Form files * Using relative paths for files inside the collection's folder --------- Co-authored-by: Mateo Gallardo <[email protected]>
- Loading branch information
1 parent
a97adbb
commit 634f9ca
Showing
13 changed files
with
220 additions
and
45 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/bruno-app/src/components/FilePickerEditor/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { browseFiles } from 'providers/ReduxStore/slices/collections/actions'; | ||
import { IconX } from '@tabler/icons'; | ||
|
||
const FilePickerEditor = ({ value, onChange, collection }) => { | ||
const dispatch = useDispatch(); | ||
const filnames = value | ||
.split('|') | ||
.filter((v) => v != null && v != '') | ||
.map((v) => v.split('\\').pop()); | ||
const title = filnames.map((v) => `- ${v}`).join('\n'); | ||
|
||
const browse = () => { | ||
dispatch(browseFiles()) | ||
.then((filePaths) => { | ||
// If file is in the collection's directory, then we use relative path | ||
// Otherwise, we use the absolute path | ||
filePaths = filePaths.map((filePath) => { | ||
const collectionDir = collection.pathname; | ||
|
||
if (filePath.startsWith(collectionDir)) { | ||
return filePath.substring(collectionDir.length + 1); | ||
} | ||
|
||
return filePath; | ||
}); | ||
|
||
onChange(filePaths.join('|')); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
const clear = () => { | ||
onChange(''); | ||
}; | ||
|
||
const renderButtonText = (filnames) => { | ||
if (filnames.length == 1) { | ||
return filnames[0]; | ||
} | ||
return filnames.length + ' files selected'; | ||
}; | ||
|
||
return filnames.length > 0 ? ( | ||
<div | ||
className="btn btn-secondary px-1" | ||
style={{ fontWeight: 400, width: '100%', textOverflow: 'ellipsis', overflowX: 'hidden' }} | ||
title={title} | ||
> | ||
<button className="align-middle" onClick={clear}> | ||
<IconX size={18} /> | ||
</button> | ||
| ||
{renderButtonText(filnames)} | ||
</div> | ||
) : ( | ||
<button className="btn btn-secondary px-1" style={{ width: '100%' }} onClick={browse}> | ||
Select Files | ||
</button> | ||
); | ||
}; | ||
|
||
export default FilePickerEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.