Skip to content

Commit

Permalink
Triming down the opts
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeymond committed Mar 28, 2024
1 parent daf58ac commit b76556f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ identified with the parameter 'file'.

``` javascript
var multer = require('multer')
var {MulterSaveFilesOrgStorage} = require('multer-savefilesorg-storage')

this.routePost('/uploadFile',
(req, res, next) => {
multer({
storage: MulterSaveFilesOrgStorage(
{
serverPath: `https://savefiles.org/api/v1/uploads`,
apiAccessToken: '<create access token under account settings>',
fileParamName: 'file' // If left blank, this defaults to 'file',
relativePath: '/' // If left blank, this defaults to root of drive '/',
}),
preservePath: true
}).array('file')(req, res, next)
}, (req, res, next) => {
res.send('Success!')
})
var {multerSaveFilesOrgStorage} = require('multer-savefilesorg-storage')

// Configure upload middleware
const upload = multer({
storage: multerSaveFilesOrgStorage({
apiAccessToken: process.env.SAVEFILESORG_API_KEY,
relativePath: '/' // If left blank, this defaults to root of drive '/',
}),
preservePath: true
});

// Use upload middleware
router.post('/', upload.single('image'), (req, res, next) => {
console.log(req.file); // If single upload was done
console.log(req.files); // If array upload was done
});
```

## License
Expand Down
6 changes: 2 additions & 4 deletions lib/multer-savefilesorg-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import FormData from 'form-data'
The data is forwarded as multipart/form-data.
opts: {
serverPath: 'https://savefiles.org/api/v1/uploads',
apiAccessToken: '<create access token under account settings>',
fileParamName: 'file' // If left blank, this defaults to 'file',
relativePath: '/' // If left blank, this defaults to root of drive '/',
}
Expand All @@ -26,11 +24,11 @@ class MulterSaveFilesOrgStorage {
_handleFile(req, file, cb) {
var form = new FormData()
// Use filepath to specify the file's fullpath. If we use filename, it'll be cut down into only the filename
form.append(this.opts.fileParamName || 'file', file.stream, { filepath: file.originalname })
form.append('file', file.stream, { filepath: file.originalname })
form.append('relativePath', this.opts.relativePath || '/')
form.pipe(concat({ encoding: 'buffer' }, data => {
axios.post(
this.opts.serverPath,
`https://savefiles.org/api/v1/uploads`,
data,
{
headers: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multer-savefilesorg-storage",
"version": "1.0.6",
"version": "1.0.7",
"description": "Forward multipart/form-data file upload into a savefiles.org drive.",
"main": "index.js",
"exports": {
Expand Down

0 comments on commit b76556f

Please sign in to comment.