Skip to content

Commit 0feea3e

Browse files
authored
Merge pull request #1756 from Platform-OS/z-x-patch-1
Enhance user uploads documentation and form handling
2 parents 8068584 + 11e8f69 commit 0feea3e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

app/views/pages/developer-guide/user-uploads/user-uploads.liquid

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,26 @@ properties:
6565
}
6666
}
6767
{% endgraphql %}
68-
<form action="{{ data.property_upload_presigned_url.upload_url }}">
68+
<form action="{{ data.property_upload_presigned_url.upload_url }}" enctype="multipart/form-data" method="post">
6969
{% for field in data.property_upload_presigned_url.upload_url_payload %}
7070
<input type="hidden" name="{{ field[0] }}" value='{{ field[1] }}'>
7171
{% endfor %}
72+
<button type="submit">Upload</button>
7273
</form>
7374
```
7475
{% endraw %}
7576

7677
3. S3: Return URL to file
77-
S3 will return status 204 and an XML response with the URL to the file on S3, if everything went well. Otherwise it will return status 4xx and the reason for the error in XML format.
78+
After submitting such form, you will be redirected to an XML response (204 status code) with the URL to the file on the storage servers. Otherwise it will return status 4xx and the reason for the error in XML format.
7879

79-
4. Browser: POST URL to application
80-
Until now, platformOS doesn't know anything about the file that the user has been uploading. This step is meant to change that. Using any method you wish, you need to send the URL to the uploaded file to the application server. Because `file` is just an URL (string) property in a record, you update that property just like any other.
80+
Please note that for optimal user experience, you would likely want to do this using an `fetch` request from JavaScript, so that the whole upload process stays invisible to the end user.
8181

82-
5. Application: Save URL to the database
83-
After getting the URL to a file from the browser, usually you want this URL to be saved in a record for future reference. You store it the same way as any other string - if the property type is `upload`, we will do all the magic behind the scenes:
82+
Be mindful that until now, platformOS doesn't know anything about the file that the user has uploaded. It exists only on the storage servers.
83+
84+
4. Application: Save URL to the database
85+
After getting the uploaded file URL you would likely want to store it in the database for future reference.
86+
87+
You store it the same way as any other string:
8488

8589
```graphql
8690
mutation record_create($direct_url: String!) {
@@ -94,14 +98,17 @@ mutation record_create($direct_url: String!) {
9498
}
9599
}
96100
```
101+
If, in the schema, you've set the property type to be `upload` then platformOS will update the field automatically after that. It will change the string you've provided to a JSON object containing additional information except the file URL. Additionally, for images, it can generate variants and URLs to those will also be automatically added to the record.
97102

98103
When you need the URL to the file, as always, you need to use GraphQL and query for the record containing the property to get it using `property_upload`, for example:
99104

100105
```graphql
101106
query get_documents {
102107
records(per_page: 20 filter: { table: { value: "documents" } }) {
103108
results {
104-
my_upload: property_upload(name: "resume") { url }
109+
my_upload: property_upload(name: "resume") {
110+
url
111+
}
105112
}
106113
}
107114
}

0 commit comments

Comments
 (0)