Skip to content

Storage

Uploading file

File uploading can be done in 2 ways

  1. Using multipart upload
  2. Using body.contenDataUri payload

Requirements

  1. Uploader must be authenticated

Using multipart upload

This is provided so auto-upload components can directly use the endpoint for uploading

Upload a file using the .file form field

sh
curl https://api.mycure.md/storage/files \
 -H "Authorization: Bearer myaccesstoken" \
 -F file@'path/to/file.pdf;type=application/pdf' \
 -F owner='acct_myuid'

# returns
# {
#   id: fileid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }
curl https://api.mycure.md/storage/files \
 -H "Authorization: Bearer myaccesstoken" \
 -F file@'path/to/file.pdf;type=application/pdf' \
 -F owner='acct_myuid'

# returns
# {
#   id: fileid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }

The request above is the same as if the ff HTML were submitted

html
<form enctype="multipart/form-data" method="post" action="https://api.mycure.md/storage/files">
    <input type="file" name="file" />
    <input type="text" name="owner" />
</form>
<form enctype="multipart/form-data" method="post" action="https://api.mycure.md/storage/files">
    <input type="file" name="file" />
    <input type="text" name="owner" />
</form>

Using body.contentDataUri payload

The js sdk uses this method

sh
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/pdf;base64,<base64versionoffile>",
  "owner": "account_myuid"
 }'

# returns
# {
#   id: fileid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/pdf;base64,<base64versionoffile>",
  "owner": "account_myuid"
 }'

# returns
# {
#   id: fileid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }

Sharing/Viewing file

The response .url field on the response body after uploading is not viewable without authentication. In case you want to view the file in the browser or share it, one must create a Link for the file with appropriate expiration

sh
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "file": "file.id",
 }'

# returns
# {
#   id: linkid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/links/linkid?content=1'
# }
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "file": "file.id",
 }'

# returns
# {
#   id: linkid,
#   ...other fields,
#   url: 'https://api.mycure.md/storage/links/linkid?content=1'
# }

Converting file to pdf

Uploaded files can be automatically converted into pdfs (currently only supports uploaded html files)

sh
# Conversion using default settings
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": true
 }'

# returns
# {
#   id: fileid,
#   ...other fields,
#   contentType: 'application/pdf',
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }

# Conversion using custom width/height
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": {
    "width": "500px",
    "height": "500px"
  }
 }'

# Conversion using preset paper format
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": {
    "paperFormat": "A4"
  }
 }'
# Conversion using default settings
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": true
 }'

# returns
# {
#   id: fileid,
#   ...other fields,
#   contentType: 'application/pdf',
#   url: 'https://api.mycure.md/storage/files/fileid?content=1'
# }

# Conversion using custom width/height
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": {
    "width": "500px",
    "height": "500px"
  }
 }'

# Conversion using preset paper format
curl https://api.mycure.md/storage/files \
 -H "ContentType: application/json" \
 -H "Authorization: Bearer myaccesstoken" \
 -F '{
  "contentDataURI": "data:application/html;base64,<base64versionoffile>",
  "owner": "account_myuid",
  "convertToPDF": {
    "paperFormat": "A4"
  }
 }'

Released under the MIT License.