FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jamstack-cms/src/utils/saveFile.js at master · jamstack-cms/jamstack-cms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
jamstack-cms
/
jamstack-cms
Public
Notifications
You must be signed in to change notification settings
Fork
67
Star
722
Code
Issues
11
Pull requests
22
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
jamstack-cms
/
src
/
utils
/
saveFile.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (25 loc) · 815 Bytes
Breadcrumbs
jamstack-cms
/
src
/
utils
/
saveFile.js
Copy path
File metadata and controls
28 lines (25 loc) · 815 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import
{
Storage
}
from
'aws-amplify'
import
config
from
'../../jamstack-config.js'
import
uuid
from
'uuid/v4'
import
{
getCleanedFileName
}
from
'./helpers'
const
{
aws_user_files_s3_bucket_region
:
region
,
aws_user_files_s3_bucket
:
bucket
}
=
config
function
saveFile
(
file
)
{
return
new
Promise
(
async
(
resolve
)
=>
{
const
{
name
:
fileName
,
type
:
mimeType
}
=
file
const
cleanedFileName
=
getCleanedFileName
(
fileName
)
const
key
=
`images/
${
uuid
(
)
}
_
${
cleanedFileName
}
`
try
{
const
imageInfo
=
await
Storage
.
put
(
key
,
file
,
{
contentType
:
mimeType
}
)
const
url
=
`https://
${
bucket
}
.s3.
${
region
}
.amazonaws.com/public/
${
imageInfo
.
key
}
`
resolve
(
{
key
:
imageInfo
.
key
,
url
}
)
}
catch
(
err
)
{
console
.
log
(
'error: '
,
err
)
}
}
)
}
export
default
saveFile
Back
|
FazBrowse Home
|
New Git URL