Skip to content

Commit

Permalink
Merge branch 'upload-files' into 'dev'
Browse files Browse the repository at this point in the history
Upload files

See merge request manuscript/surix/app-service!15
  • Loading branch information
grafitto committed Nov 20, 2018
2 parents f8b4624 + 1dccf32 commit 9613128
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 13 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const requests = Surix.requests;
- `updateTag`: Updates the specified tag in an entity. <!--readme added-->
- `project`: Fetches the current Surix project.
- `getAppData`: Fetches app data stored by the app in the current project
- `updateAppData`: Updates/adds app data to the current project
- `updateAppData`: Updates/adds app data to the current project.
- `createFile`: Creates a file in the current Surix project (expects fileParams: any parameter).
- `getFiles`: Queries files from the current Surix project.
- `getFileById`: Gets a single file by its Surix id.

`requests.toast` contains:
- `show`: Displays a message on Surix toast (expects message: string parameter).
Expand Down Expand Up @@ -241,6 +244,47 @@ service.request(requests.data.updateAppData, update).then(updatedData => {
// handler error
});
```
### Upload a file:
```javascript

const file = document.getElementById('file'); // Assuming the element is an input of type file

const fileParmas = {
name: 'My picture', // File title
mimeType: file.type, // Image mime type (this type is checked against the type of the file itself)
public: true // Is the file publicly accessible?
file, // The file itself (has to be of type File)
}

service.request(requests.data.createFile, fileParams).then(fileDetails => {
// Do something with the file details
}).catch(err => {
// Handle error
})
```

### Fetch a file by ID
```javascript
const fileId = '123';

service.request(requests.data.getFileById, fileId).then(fileDetails => {
// Do something with the fileDetails
// NOTE: fileDetails has field downloadUrl that contains a url
// to the actual file
}).catch(err => {
// Handle error
});
```

### Fetch all files
```javascript

service.request(requests.data.getFiles).then(files => {
// DO something with the files, file is an array of fileDetails
}).catch(err => {
// Handle error
})
```

## Events:
There are times where Surix sends information to the app without the app requesting.
Expand Down
7 changes: 7 additions & 0 deletions build/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion build/dist/src/requests.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ export declare const requests: {
addTagsToEntity: string;
removeTagsFromEntity: string;
getTags: string;
updateTag: string,
updateTag: string;
getAppData: string;
updateAppData: string;
createFile: string;
getFileById: string;
getFiles: string;
};
toast: {
show: string;
Expand Down
30 changes: 30 additions & 0 deletions build/dist/src/requests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/dist/src/requests.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions build/dist/src/service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/dist/src/service.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions dist/client-service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9613128

Please sign in to comment.