Does anybody know how to realize uploading files in parse-server 6.0.0 ?
Where I can read about it?
The parse-server docs is a hell for beginners!
Do you have a specific problem? What client platform are you using? What have you tried so far? Please help the community help you
To get you started: hereās the JavaScript File docs , which I found very approachable.
Thanks.
Iāve read this guide as well as others but in my opinion there is critically little information in these documents:
https://docs.parseplatform.org/js/guide/#creating-a-parsefile
https://docs.parseplatform.org/rest/guide/#uploading-files
https://docs.parseplatform.org/graphql/guide/#create-a-file
Soā¦
For example, when I try to follow guidesā examples and try to upload a file (via Parse Dashboard GraphQL API Console) I receive an error:
āupload.arrayBuffer is not a functionā. Where can I find an answer - why?
Hi @VKlapan this topic was answered on GitHub.
opened 10:34AM - 06 Apr 23 UTC
closed 08:44PM - 14 Feb 24 UTC
type:question
state:released
state:released-alpha
state:released-beta
### New Issue Checklist
<!--
Check every following box [x] before submittiā¦ ng your issue.
Click the "Preview" tab for better readability.
Thanks for contributing to Parse Platform!
-->
- [x] I am not disclosing a [vulnerability](https://github.com/parse-community/parse-server/blob/master/SECURITY.md).
- [x] I am not just asking a [question](https://github.com/parse-community/.github/blob/master/SUPPORT.md).
- [x] I have searched through [existing issues](https://github.com/parse-community/parse-server/issues?q=is%3Aissue).
- [x] I can reproduce the issue with the [latest version of Parse Server](https://github.com/parse-community/parse-server/releases).
### Issue Description
When I try to upload a file (via Parse Dashboard GraphQL API Console) I receive an error:
"upload.arrayBuffer is not a function".
Do not understand - what is wrong?
### Steps to reproduce
Try to check file uploading via Parse Dashboard GraphQL API Console.
Query:
`
mutation createFile($file: Upload!) {
createFile(input: {upload:$file}) {
fileInfo {
name
url
}
}
}
`
Variables - base64 string:
`
{
"file":"V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE="
}
`
### Actual Outcome
Response:
`
{
"errors": [
{
"message": "upload.arrayBuffer is not a function",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createFile"
]
}
],
"data": {
"createFile": null
}
}
`
### Expected Outcome
### Environment
Server
- Parse Server version: `6.0.0`
- Operating system: `Linux Mint 20.2 Cinnamon and docker`
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): `local`
Database
- System (MongoDB or Postgres): `MongoDB`
- Database version: `mongo:4`
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): `local`
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc): `JavaScript`
- SDK version: ` "@types/parse": "^2.18.13"`
### Logs
server config:
`
Successfully compiled 1 file with Babel (297ms).
SERVER CONFIG
Configuration loaded from /parse-server/config/server.js
warn: DeprecationWarning: The Parse Server option 'allowClientClassCreation' default will change to 'false' in a future version.
warn: DeprecationWarning: The Parse Server option 'allowExpiredAuthDataToken' default will change to 'false' in a future version.
RUN Parse Server Cloud
allowClientClassCreation: true
allowCustomObjectId: false
allowExpiredAuthDataToken: true
allowHeaders: ["X-Apollo-Tracing"]
appId: parse-template
appName: Parse Template
cacheMaxSize: 10000
cacheTTL: 5000
cloud: /parse-server/cloud-dist
collectionPrefix:
customPages: {"invalidLink":"http://localhost/invalid-link","invalidVerificationLink":"http://localhost/invalid-verification-link","passwordResetSuccess":"http://localhost/password-reset-success","choosePassword":"http://localhost/choose-password"}
databaseURI: mongodb://db/parse
defaultLimit: 100
directAccess: true
emailAdapter: {"options":{"service":"SMTP","fromAddress":"dev@******.com","user":"dev@*****","password":"******","host":"mail.****.com","port":587,"isSSL":false,"templates":{"resetPassword":{"path":"/parse-server/templates/reset-password","subject":"Password reset"},"verifyEmail":{"path":"/parse-server/templates/verify-email","subject":"Email verification"}}}}
emailVerifyTokenReuseIfValid: false
emailVerifyTokenValidityDuration: 7200
enableAnonymousUsers: true
enableExpressErrorHandler: false
enforcePrivateUsers: true
expireInactiveSessions: true
filesAdapter: {"_encryptionKey":null,"_filesDir":"/parse-server/files"}
fileUpload: {"enableForPublic":true,"enableForAnonymousUser":true,"enableForAuthenticatedUser":true}
graphQLPath: /graphql
graphQLSchema: /parse-server/schema.graphql
host: 0.0.0.0
idempotencyOptions: {"ttl":300,"paths":[]}
liveQuery: {"classNames":[]}
logLevel: warn
logLevels: {"triggerAfter":"info","triggerBeforeError":"error","triggerBeforeSuccess":"info"}
logsFolder: ./logs
maintenanceKeyIps: ["127.0.0.1","::1"]
masterKey: ***REDACTED***
masterKeyIps: ["172.30.0.0/16"]
maxUploadSize: 4000mb
mountGraphQL: true
mountPath: /
mountPlayground: false
objectIdSize: 10
pages: {"enableRouter":false,"enableLocalization":false,"localizationFallbackLocale":"en","placeholders":{},"forceRedirect":false,"pagesPath":"./public","pagesEndpoint":"apps","customUrls":{},"customRoutes":[]}
passwordPolicy: {"doNotAllowUsername":true,"resetTokenValidityDuration":10800}
playgroundPath: /playground
port: 1337
preserveFileName: false
preventLoginWithUnverifiedEmail: false
protectedFields: {"_User":{"*":["email"],"role:admin":[]}}
publicServerURL: http://localhost:1337
rateLimit: []
requestKeywordDenylist: [{"key":"_bsontype","value":"Code"},{"key":"constructor"},{"key":"__proto__"}]
restAPIKey: asd78sd897df09as87dfh09asd
revokeSessionOnPasswordReset: true
scheduledPush: false
security: {"enableCheck":false,"enableCheckLog":false}
sessionLength: 31536000
startLiveQueryServer: true
trustProxy: []
verbose: false
verifyUserEmails: true
jsonLogs: false
level: undefined
serverURL: http://localhost:1337/
state: initialized
`
Unfortunately not.
This is my topic and it is open for me yet.
Iāve sent another question at that topic and can gladly re-post it here:
Soā¦
Iāve tried to use information from examples: GitHub - jaydenseric/graphql-multipart-request-spec: A spec for GraphQL multipart form requests (file uploads).
but with zero result (
For example, I have a question:
Is this example correct and it has to work?
A spec for GraphQL multipart form requests (file uploads).
But I have error: {āerrorā:āUnexpected token - in JSON at position 0ā}
Why?
Here is how to upload a file image via JS SDK,
Frontend:
Parse.initialize(process.env.NEXT_PUBLIC_APP_ID);
Parse.serverURL = `${process.env.NEXT_PUBLIC_SERVER_URL}/parse`;
const newImage = new Parse.File("image.png", { base64: //base 64 string | you can get it from canvas.toDataURL(ctx) });
await newImage.save();
const response = await Parse.Cloud.run("uploadProfileImage", {
url: newImage.url(),
});
Server:
Parse.Cloud.define("uploadProfileImage", async (req) => {
const { url } = req.params;
try {
const user = await new Parse.Query(Parse.User)
.equalTo("objectId", req.user.id)
.first({useMasterKey:true});
if (user) {
user.set("img", url);
}
await user.save(null, {useMasterKey:true});
return {sts: true, msg: "image uploaded"}
} catch (err) {
throw err;
});
Note that if you want your files to be stored in a bucket like AWS S3 or DO spaces you need to configure the adapted in the server settings.
For videos use:
const newVideo = new Parse.File("video.mp4", { uri: data.vUrl });
await newVideo.save();
With this approach, any user can modify another usersā profile image as long as they have their userId (or guess it), which could be problematic.
A refactor of this cloud function would be:
Parse.Cloud.define("uploadProfileImage", async (req) => {
const { url } = req.params;
const user = req.user;
user.set("img", url);
await user.save(null, {useMasterKey:true});
return {sts: true, msg: "image uploaded"}
}, {
requireUser: true,
fields: ['url']
});
More preferred you should be able to do it all on the frontend:
Parse.initialize(process.env.NEXT_PUBLIC_APP_ID);
Parse.serverURL = `${process.env.NEXT_PUBLIC_SERVER_URL}/parse`;
const newImage = new Parse.File("image.png", { base64: //base 64 string | you can get it from canvas.toDataURL(ctx) });
await newImage.save();
const user = Parse.User.current();
user.set("img", newImage);
await user.save();
1 Like
A few more details:
I have this error on my parse server 6.0.0 :
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Does anybody know how to fix it ?
Make sure youāre not calling res.send()
or res.json()
more than once in a single request
I might be wrong but check that your input is { base64: // base 64 string }, and not just //base 64 string. I.e. the function accepts an object with a base64 key. So make sure your input is formatted like so.
I have a differnt issue - after uploaded - the video wonāt play on Chrome. - plays on safari and firefox and other vides do play on chrome - i uploded one that plays on chrome - then after the upload it wonāt play