saasufy-components 10.5.1 → 10.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,26 +211,45 @@ After adding a record to Saasufy which holds a file in one of its fields, that f
|
|
|
211
211
|
The format of the URL to link directly to a specific file/image is:
|
|
212
212
|
|
|
213
213
|
```
|
|
214
|
-
https
|
|
214
|
+
https://:serviceId.saasufy.com/files/:modelName/:modelId/:fieldName
|
|
215
215
|
```
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
Each service serves its files on a subdomain of its own, named after the service.
|
|
217
|
+
The `:serviceId` is the `sid` part of the URL for your Saasufy service (which you get after deploying your service); if that URL is `wss://saasufy.com/sid7999/socketcluster/`, then your service ID is `sid7999`.
|
|
218
|
+
|
|
219
|
+
So if your file is stored inside an `Image` model with ID `58f2051c-14bc-4518-8816-ff387cfdd57e` inside a `data` field, you will be able to link to your image directly using this URL:
|
|
218
220
|
|
|
219
221
|
```
|
|
220
|
-
https://saasufy.com/
|
|
222
|
+
https://sid7999.saasufy.com/files/Image/58f2051c-14bc-4518-8816-ff387cfdd57e/data
|
|
221
223
|
```
|
|
222
224
|
|
|
223
225
|
You can use it to embed images into your application using the `<img>` tag like this:
|
|
224
226
|
|
|
225
227
|
```html
|
|
226
|
-
<img src="https://saasufy.com/
|
|
228
|
+
<img src="https://sid7999.saasufy.com/files/Image/58f2051c-14bc-4518-8816-ff387cfdd57e/data" alt="My image" />
|
|
227
229
|
```
|
|
228
230
|
|
|
229
231
|
Saasufy enforces access controls for HTTP in the same way as it does for its WebSocket protocol.
|
|
230
232
|
It's possible to block or restrict access to specific files stored on specific fields via the `Access` page under the relevant model.
|
|
231
233
|
|
|
232
234
|
If your model field's access is set to `restrict`, only authenticated users with matching permissions will be able to view/download the image/file.
|
|
233
|
-
In this case
|
|
235
|
+
In this case the request has to carry the user's signed JWT in an `Authorization: Bearer <signedAuthToken>` header; the token is the `signedAuthToken` of your `socket-provider`'s socket.
|
|
236
|
+
|
|
237
|
+
Headers cannot be attached to an `<img src="...">`, so fetch the file yourself and hand the element an object URL:
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
let socket = document.querySelector('socket-provider').saasufySocket;
|
|
241
|
+
|
|
242
|
+
let response = await fetch('https://sid7999.saasufy.com/files/Image/58f2051c-14bc-4518-8816-ff387cfdd57e/data', {
|
|
243
|
+
headers: { Authorization: `Bearer ${socket.signedAuthToken}` }
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
let img = document.querySelector('img');
|
|
247
|
+
img.src = URL.createObjectURL(await response.blob());
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Remember to `URL.revokeObjectURL(img.src)` once you are done with it.
|
|
251
|
+
|
|
252
|
+
Because files are served on a subdomain of their own, that fetch is a cross-origin request and the browser preflights it. Your app's origin therefore has to appear in the **Files allow origin** setting on the Saasufy settings page, which defaults to `*`. Files which are not restricted need none of this - an `<img>` tag is not subject to CORS.
|
|
234
253
|
|
|
235
254
|
## Components
|
|
236
255
|
|