Skip to navigation

Write a file, or unpack a tar into a directory

Without archive, writes the request body to the file at path, creating parent directories and replacing an existing file.

With archive=tar, unpacks the body, an uncompressed tar, into the directory at path, creating it if needed. Entry paths must be relative and stay inside path. A link that points outside it returns 400.

Files are written as the image’s default user, which is root for most images. A single file gets mode 0644. Entries of a tar keep the mode and the numeric owner recorded in the archive. There is no parameter for the owner or the mode, and an unknown query parameter is ignored. To let another user write to the files, run chown or chmod with exec afterwards.

The upload is all or nothing for an archive Meadow refuses. Meadow checks the whole body before the sandbox unpacks any of it, so a 400 invalid tar archive (a gzipped tar, a body that is not a tar, a tar that is cut short or whose length is not a multiple of 512 bytes) or a 400 for an entry that leaves path writes no file. On Modal the empty directory at path may have been created.

One case can still write some entries: the archive passes Meadow’s check and the tar program inside the sandbox then fails part of the way through, for example on a full disk or a directory it may not write to. That returns 400 the sandbox could not unpack the tar archive; some entries may have been written. Remove the directory with exec before you send it again.

The body is at most 100 MiB. A larger one returns 413. The upload must finish within 10 minutes. The call counts as sandbox activity while it is open.

Scope: sandboxes.

curl -sS -X PUT "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX_ID/files?path=/tmp/data/notes.txt" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary @notes.txt
tar -cf - -C ./project . | curl -sS -X PUT \
"$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX_ID/files?path=/tmp/project&archive=tar" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary @-

Authentication

AuthorizationBearer

A Meadow API key, sent as Authorization: Bearer mdw_.... The header x-api-key: mdw_... is accepted in its place.

Path parameters

sandbox_idstringRequired

The sandbox id returned by POST /v1/sandboxes. It must belong to the key’s project.

Query parameters

pathstringRequired

Absolute path inside the sandbox, at most 4096 bytes, with no .. segment. For a single file it must not end with /.

archiveenumOptional

Set to tar to send or receive a directory as an uncompressed tar stream. Entries are relative to path, with no top-level folder. Any other value returns 400.

Allowed values:

Request

The file’s bytes, or an uncompressed tar when archive=tar. At most 100 MiB.

Response

Written. No body.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
413
Content Too Large Error
429
Too Many Requests Error
500
Internal Server Error
502
Bad Gateway Error