Skip to main content
PUT
/
api
/
files
/
{fileID}
/
access
Toggle Public Access
curl --request PUT \
  --url https://api.example.com/api/files/{fileID}/access \
  --header 'Content-Type: application/json' \
  --data '{
  "public": true
}'
{
  "message": "<string>",
  "file": {
    "id": {},
    "name": "<string>",
    "location": "<string>",
    "user_id": {},
    "size": {},
    "public": true,
    "created_at": {},
    "updated_at": {}
  },
  "error": "<string>"
}

Authentication

This endpoint requires Bearer token authentication.
Authorization: Bearer YOUR_JWT_TOKEN

Request

fileID
uint
required
The unique identifier of the file to modify
public
boolean
required
Set to true to make the file publicly accessible, or false to make it private

Authorization

Only the file owner can modify access settings. Attempting to modify another user’s file will result in a 403 Forbidden error.

Response

message
string
Success confirmation message
file
object
The updated file record
id
uint
Unique file identifier
name
string
Filename
location
string
Relative file path
user_id
uint
ID of the file owner
size
int64
File size in bytes
public
boolean
Updated public access status
created_at
timestamp
File creation timestamp
updated_at
timestamp
Last modification timestamp (updated)

Error Responses

error
string
Error message describing the failure

400 Bad Request - Invalid File ID

{
  "error": "Invalid file ID"
}

400 Bad Request - Invalid Request Body

{
  "error": "Invalid request body"
}

401 Unauthorized

{
  "error": "User not authenticated"
}

403 Forbidden

{
  "error": "You don't have permission to modify this file"
}

404 Not Found

{
  "error": "File not found"
}

500 Internal Server Error

{
  "error": "Failed to update file"
}

Examples

curl -X PUT https://api.defdrive.com/api/files/42/access \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{"public": true}'

Success Response Example

{
  "message": "File access updated successfully",
  "file": {
    "id": 42,
    "name": "document.pdf",
    "location": "johndoe/document.pdf",
    "user_id": 15,
    "size": 2048576,
    "public": true,
    "created_at": "2026-03-04T10:30:00Z",
    "updated_at": "2026-03-04T14:22:00Z"
  }
}
This endpoint updates the public field in the database. When public is set to true, the file becomes accessible through public sharing mechanisms. When false, only the owner (or users with explicit access grants) can access the file.
The file ID is parsed as an unsigned 32-bit integer. File IDs larger than 4,294,967,295 will result in a 400 Bad Request error.

Build docs developers (and LLMs) love