import{r as o,p as c,q as h,w as l,z as e,t as a,R as s}from"./vendor.8ed37afc.js";var d="assets/original.888775a8.jpg",u="data:image/jpeg;base64, ",p="assets/200-200-cover-50.b5c757be.jpg",f="assets/200-200-cover-75.5e0d9ff8.jpg",_="assets/200-200-cover-100.6a119754.jpg";const g={class:"markdown-body"},m=e("div",{class:"two-up"},[e("div",{class:"left"},[e("blockquote",null,[e("p",null,[s("Every file managed by the platform is uploaded to the configured storage adapter, and its associated metadata is tracked within the "),e("code",null,"directus_files"),s(" system collection. Any requested file transformations are handled on the fly, and are only saved to storage.")])])]),e("div",{class:"right"},[e("p",null,[e("div",{class:"table-of-contents"},[e("ul",null,[e("li",null,[e("a",{href:"#accessing-an-file"},"Accessing an File")]),e("li",null,[e("a",{href:"#downloading-a-file"},"Downloading a File")]),e("li",null,[e("a",{href:"#requesting-a-thumbnail"},"Requesting a Thumbnail")]),e("li",null,[e("a",{href:"#the-file-object"},"The File Object")]),e("li",null,[e("a",{href:"#list-files"},"List Files")]),e("li",null,[e("a",{href:"#retrieve-a-file"},"Retrieve a File")]),e("li",null,[e("a",{href:"#upload-a-file"},"Upload a File")]),e("li",null,[e("a",{href:"#import-a-file"},"Import a File")]),e("li",null,[e("a",{href:"#update-a-file"},"Update a File")]),e("li",null,[e("a",{href:"#update-multiple-files"},"Update Multiple Files")]),e("li",null,[e("a",{href:"#delete-a-file"},"Delete a File")]),e("li",null,[e("a",{href:"#delete-multiple-files"},"Delete Multiple Files")])])])])])],-1),y=e("hr",null,null,-1),j=e("h2",{id:"accessing-an-file"},[s("Accessing an File "),e("a",{class:"header-anchor",href:"#accessing-an-file"},"#")],-1),b=e("div",{class:"two-up"},[e("div",{class:"left"},[e("p",null,"The location of your actual file originals is based on the project\u2019s configuration, but you can consistently access them via the API using the following URL."),e("pre",null,[e("code",null,`example.com/assets/<file-id>
example.com/assets/1ac73658-8b62-4dea-b6da-529fbc9d01a4
`)]),e("div",{class:"warning hint"},[e("div",{class:"hint-title"},"Direct File Access"),e("p",null,[s("While you may "),e("em",null,"technically"),s(" be able to expose your storage adapters root filesystem and access your raw files through there, it is recommended that you always use the Directus API. This is the only way that you can take advantage of file permissions and other built-in features.")])])]),e("div",{class:"right"},[e("p",null,[e("img",{src:d,alt:"Original File"}),s(),e("em",null,"Original File Used \u2014 602KB and 1800x1200")])])],-1),A=e("hr",null,null,-1),q=e("h2",{id:"downloading-a-file"},[s("Downloading a File "),e("a",{class:"header-anchor",href:"#downloading-a-file"},"#")],-1),x=e("div",{class:"two-up"},[e("div",{class:"left"},[e("p",null,[s("To download an asset with the correct filename, you need to add the "),e("code",null,"?download"),s(" query parameter to the request and the "),e("code",null,"download"),s(" attribute to your anchor tag. This will ensure the appropriate "),e("a",{href:"https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html",target:"_blank",rel:"noopener noreferrer"},"Content-Disposition"),s(" headers are added. Without this, the download will work on the "),e("em",null,"same"),s(" domain, however it will have the file\u2019s \u201Cid\u201D as the filename for cross-origin requests.")])]),e("div",{class:"right"},[e("h3",{id:"example"},[s("Example "),e("a",{class:"header-anchor",href:"#example"},"#")]),e("pre",null,[e("code",{class:"language-html"},[e("span",{class:"hljs-tag"},[s("<"),e("span",{class:"hljs-name"},"a"),s(),e("span",{class:"hljs-attr"},"href"),s("="),e("span",{class:"hljs-string"},'"https://your-directus.com/assets/<file-id>?download"'),s(),e("span",{class:"hljs-attr"},"target"),s("="),e("span",{class:"hljs-string"},'"_blank"'),s(),e("span",{class:"hljs-attr"},"download"),s("="),e("span",{class:"hljs-string"},'"Your File.pdf"'),s(">")]),s("Download"),e("span",{class:"hljs-tag"},[s("</"),e("span",{class:"hljs-name"},"a"),s(">")]),s(`
`)])])])],-1),w=e("hr",null,null,-1),R=e("h2",{id:"requesting-a-thumbnail"},[s("Requesting a Thumbnail "),e("a",{class:"header-anchor",href:"#requesting-a-thumbnail"},"#")],-1),T={class:"two-up"},v={class:"left"},U=e("p",null,[s("Fetching thumbnails is as easy as adding a "),e("code",null,"key"),s(" query parameter to the original file\u2019s URL. In the Admin App, you can configure different asset presets that control the output of any given image. If a requested thumbnail doesn\u2019t yet exist, it is dynamically generated and immediately returned.")],-1),k=e("h3",{id:"preset-transformations"},[s("Preset Transformations "),e("a",{class:"header-anchor",href:"#preset-transformations"},"#")],-1),B=e("strong",null,[e("code",null,"key")],-1),E=s(" \u2014 This "),I=e("strong",null,"key",-1),Q=s(" of the "),S=s("Storage Asset Preset"),D=s(", a shortcut for the below parameters"),F=e("h3",{id:"custom-transformations"},[s("Custom Transformations "),e("a",{class:"header-anchor",href:"#custom-transformations"},"#")],-1),O=e("p",null,"Alternatively, if you have \u201CStorage Asset Transform\u201D set to all, you can use the following parameters for more fine grained control:",-1),C=e("ul",null,[e("li",null,[e("strong",null,[e("code",null,"fit")]),s(" \u2014 The "),e("strong",null,"fit"),s(" of the thumbnail while always preserving the aspect ratio, can be any of the following options: "),e("ul",null,[e("li",null,[e("code",null,"cover"),s(" \u2014 Covers both width/height by cropping/clipping to fit")]),e("li",null,[e("code",null,"contain"),s(" \u2014 Contain within both width/height using \u201Cletterboxing\u201D as needed")]),e("li",null,[e("code",null,"inside"),s(" \u2014 Resize to be as large as possible, ensuring dimensions are less than or equal to the requested width and height")]),e("li",null,[e("code",null,"outside"),s(" \u2014 Resize to be as small as possible, ensuring dimensions are greater than or equal to the requested width and height")])])]),e("li",null,[e("strong",null,[e("code",null,"width")]),s(" \u2014 The "),e("strong",null,"width"),s(" of the thumbnail in pixels")]),e("li",null,[e("strong",null,[e("code",null,"height")]),s(" \u2014 The "),e("strong",null,"height"),s(" of the thumbnail in pixels")]),e("li",null,[e("strong",null,[e("code",null,"quality")]),s(" \u2014 The optional "),e("strong",null,"quality"),s(" of the thumbnail ("),e("code",null,"1"),s(" to "),e("code",null,"100"),s(")")]),e("li",null,[e("strong",null,[e("code",null,"withoutEnlargement")]),s(" \u2014 Disable image up-scaling")]),e("li",null,[e("strong",null,[e("code",null,"format")]),s(" \u2014 What file format to return the thumbnail in. One of "),e("code",null,"jpg"),s(", "),e("code",null,"png"),s(", "),e("code",null,"webp"),s(", "),e("code",null,"tiff")])],-1),G=e("h3",{id:"advanced-transformations"},[s("Advanced Transformations "),e("a",{class:"header-anchor",href:"#advanced-transformations"},"#")],-1),Y=e("p",null,[s("For even more advanced control over the file generation, Directus exposes "),e("a",{href:"https://sharp.pixelplumbing.com/api-operation",target:"_blank",rel:"noopener noreferrer"},[s("the full "),e("code",null,"sharp"),s(" API")]),s(" through the "),e("code",null,"transforms"),s(" query parameter. This parameter accepts a two-dimensional array with the format "),e("code",null,"[Operation, ...arguments]"),s(".")],-1),M=e("h3",{id:"quality-vs-filesize"},[s("Quality vs Filesize "),e("a",{class:"header-anchor",href:"#quality-vs-filesize"},"#")],-1),P=e("p",null,[s("The quality parameter can be any integer from "),e("code",null,"0-100"),s(". Qualities closer to "),e("code",null,"0"),s(" have lower filesizes, but also poor image quality due to compression artifacts. Values closer to "),e("code",null,"100"),s(" have larger filesizes, but better image quality. Below are four possible qualities (200x200 cover) to visually compare the balance between compression and filesize.")],-1),K=e("table",null,[e("thead",null,[e("tr",null,[e("th",null,"25%"),e("th",null,"50%"),e("th",null,"75%"),e("th",null,"100%")])]),e("tbody",null,[e("tr",null,[e("td",null,[e("img",{src:u,alt:"25%"}),e("br"),e("em",null,"4KB")]),e("td",null,[e("img",{src:p,alt:"50%"}),e("br"),e("em",null,"6KB")]),e("td",null,[e("img",{src:f,alt:"75%"}),e("br"),e("em",null,"8KB")]),e("td",null,[e("img",{src:_,alt:"100%"}),e("br"),e("em",null,"38KB")])])])],-1),H=e("div",{class:"right"},[e("h3",{id:"preset"},[s("Preset "),e("a",{class:"header-anchor",href:"#preset"},"#")]),e("pre",null,[e("code",null,`example.com/assets/<file-id>?key=<key>
`)]),e("h3",{id:"custom"},[s("Custom "),e("a",{class:"header-anchor",href:"#custom"},"#")]),e("pre",null,[e("code",null,`example.com/assets/<file-id>?fit=<fit>&width=<width>&height=<height>&quality=<quality>
example.com/assets/1ac73658-8b62-4dea-b6da-529fbc9d01a4?fit=cover&width=200&height=200&quality=80
`)]),e("h3",{id:"advanced"},[s("Advanced "),e("a",{class:"header-anchor",href:"#advanced"},"#")]),e("pre",null,[e("code",null,`?transforms=[
	["blur", 45],
	["tint", "rgb(255, 0, 0)"],
	["expand", { "right": 200, "bottom": 150 }]
]
`)])],-1),J=e("hr",null,null,-1),W=e("h2",{id:"the-file-object"},[s("The File Object "),e("a",{class:"header-anchor",href:"#the-file-object"},"#")],-1),L={class:"two-up"},N={class:"left"},V={class:"definitions"},z=e("p",null,[e("code",null,"id"),s(),e("strong",null,"uuid"),e("br"),s(" Primary key of the file")],-1),X=e("p",null,[e("code",null,"storage"),s(),e("strong",null,"string"),e("br"),s(" Storage adapter used for the file.")],-1),Z=e("p",null,[e("code",null,"filename_disk"),s(),e("strong",null,"string"),e("br"),s(" Name of the file as saved on the storage adapter.")],-1),$=e("p",null,[e("code",null,"filename_download"),s(),e("strong",null,"string"),e("br"),s(" Preferred filename when file is downloaded.")],-1),ee=e("p",null,[e("code",null,"title"),s(),e("strong",null,"string"),e("br"),s(" Title for the file.")],-1),se=e("p",null,[e("code",null,"type"),s(),e("strong",null,"string"),e("br"),s(" Mimetype of the file.")],-1),le=e("code",null,"folder",-1),te=s(),ae=e("strong",null,"many-to-one",-1),ne=e("br",null,null,-1),oe=s(" What (virtual) folder the file is in. Many-to-one to "),ie=s("folders"),re=s("."),ce=e("code",null,"uploaded_by",-1),he=s(),de=e("strong",null,"many-to-one",-1),ue=e("br",null,null,-1),pe=s(" Who uploaded the file. Many-to-one to "),fe=s("users"),_e=s("."),ge=e("p",null,[e("code",null,"uploaded_on"),s(),e("strong",null,"datetime"),e("br"),s(" When the file was uploaded.")],-1),me=e("code",null,"modified_by",-1),ye=s(),je=e("strong",null,"many-to-one",-1),be=e("br",null,null,-1),Ae=s(" Who updated the file last. Many-to-one to "),qe=s("users"),xe=s("."),we=e("p",null,[e("code",null,"filesize"),s(),e("strong",null,"number"),e("br"),s(" Size of the file in bytes.")],-1),Re=e("p",null,[e("code",null,"width"),s(),e("strong",null,"number"),e("br"),s(" If the file is a(n) image/video, it\u2019s the width in px.")],-1),Te=e("p",null,[e("code",null,"height"),s(),e("strong",null,"number"),e("br"),s(" If the file is a(n) image/video, it\u2019s the height in px.")],-1),ve=e("p",null,[e("code",null,"duration"),s(),e("strong",null,"number"),e("br"),s(" If the file contains audio/video, it\u2019s the duration in milliseconds.")],-1),Ue=e("p",null,[e("code",null,"description"),s(),e("strong",null,"string"),e("br"),s(" Description of the file.")],-1),ke=e("p",null,[e("code",null,"location"),s(),e("strong",null,"string"),e("br"),s(" Location of the file.")],-1),Be=e("p",null,[e("code",null,"tags"),s(),e("strong",null,"array"),e("br"),s(" Tags for the file.")],-1),Ee=e("p",null,[e("code",null,"metadata"),s(),e("strong",null,"object"),e("br"),s(" Any additional metadata Directus was able to scrape from the file. For images, this includes EXIF, IPTC, and ICC information.")],-1),Ie=e("div",{class:"right"},[e("pre",null,[e("code",{class:"language-json"},[s(`{
	`),e("span",{class:"hljs-attr"},'"id"'),s(": "),e("span",{class:"hljs-string"},'"4f4b14fa-a43a-46d0-b7ad-90af5919bebb"'),s(`,
	`),e("span",{class:"hljs-attr"},'"storage"'),s(": "),e("span",{class:"hljs-string"},'"local"'),s(`,
	`),e("span",{class:"hljs-attr"},'"filename_disk"'),s(": "),e("span",{class:"hljs-string"},'"4f4b14fa-a43a-46d0-b7ad-90af5919bebb.jpeg"'),s(`,
	`),e("span",{class:"hljs-attr"},'"filename_download"'),s(": "),e("span",{class:"hljs-string"},'"paulo-silva-vSRgXtQuns8-unsplash.jpg"'),s(`,
	`),e("span",{class:"hljs-attr"},'"title"'),s(": "),e("span",{class:"hljs-string"},'"Paulo Silva (via Unsplash)"'),s(`,
	`),e("span",{class:"hljs-attr"},'"type"'),s(": "),e("span",{class:"hljs-string"},'"image/jpeg"'),s(`,
	`),e("span",{class:"hljs-attr"},'"folder"'),s(": "),e("span",{class:"hljs-literal"},"null"),s(`,
	`),e("span",{class:"hljs-attr"},'"uploaded_by"'),s(": "),e("span",{class:"hljs-string"},'"0bc7b36a-9ba9-4ce0-83f0-0a526f354e07"'),s(`,
	`),e("span",{class:"hljs-attr"},'"uploaded_on"'),s(": "),e("span",{class:"hljs-string"},'"2021-02-04T11:37:41-05:00"'),s(`,
	`),e("span",{class:"hljs-attr"},'"modified_by"'),s(": "),e("span",{class:"hljs-literal"},"null"),s(`,
	`),e("span",{class:"hljs-attr"},'"modified_on"'),s(": "),e("span",{class:"hljs-string"},'"2021-02-04T11:37:42-05:00"'),s(`,
	`),e("span",{class:"hljs-attr"},'"filesize"'),s(": "),e("span",{class:"hljs-number"},"3442252"),s(`,
	`),e("span",{class:"hljs-attr"},'"width"'),s(": "),e("span",{class:"hljs-number"},"3456"),s(`,
	`),e("span",{class:"hljs-attr"},'"height"'),s(": "),e("span",{class:"hljs-number"},"5184"),s(`,
	`),e("span",{class:"hljs-attr"},'"duration"'),s(": "),e("span",{class:"hljs-literal"},"null"),s(`,
	`),e("span",{class:"hljs-attr"},'"description"'),s(": "),e("span",{class:"hljs-literal"},"null"),s(`,
	`),e("span",{class:"hljs-attr"},'"location"'),s(": "),e("span",{class:"hljs-literal"},"null"),s(`,
	`),e("span",{class:"hljs-attr"},'"tags"'),s(": ["),e("span",{class:"hljs-string"},'"photo"'),s(", "),e("span",{class:"hljs-string"},'"pretty"'),s(`],
	`),e("span",{class:"hljs-attr"},'"metadata"'),s(`: {
		`),e("span",{class:"hljs-attr"},'"icc"'),s(`: {
			`),e("span",{class:"hljs-attr"},'"version"'),s(": "),e("span",{class:"hljs-string"},'"2.1"'),s(`,
			`),e("span",{class:"hljs-attr"},'"intent"'),s(": "),e("span",{class:"hljs-string"},'"Perceptual"'),s(`,
			`),e("span",{class:"hljs-attr"},'"cmm"'),s(": "),e("span",{class:"hljs-string"},'"lcms"'),s(`,
			`),e("span",{class:"hljs-attr"},'"deviceClass"'),s(": "),e("span",{class:"hljs-string"},'"Monitor"'),s(`,
			`),e("span",{class:"hljs-attr"},'"colorSpace"'),s(": "),e("span",{class:"hljs-string"},'"RGB"'),s(`,
			`),e("span",{class:"hljs-attr"},'"connectionSpace"'),s(": "),e("span",{class:"hljs-string"},'"XYZ"'),s(`,
			`),e("span",{class:"hljs-attr"},'"platform"'),s(": "),e("span",{class:"hljs-string"},'"Apple"'),s(`,
			`),e("span",{class:"hljs-attr"},'"creator"'),s(": "),e("span",{class:"hljs-string"},'"lcms"'),s(`,
			`),e("span",{class:"hljs-attr"},'"description"'),s(": "),e("span",{class:"hljs-string"},'"c2"'),s(`,
			`),e("span",{class:"hljs-attr"},'"copyright"'),s(": "),e("span",{class:"hljs-string"},'""'),s(`
		}
	}
}
`)])])],-1),Qe=e("hr",null,null,-1),Se=e("h2",{id:"list-files"},[s("List Files "),e("a",{class:"header-anchor",href:"#list-files"},"#")],-1),De=e("p",null,"List all files that exist in Directus.",-1),Fe={class:"two-up"},Oe={class:"left"},Ce=e("h3",{id:"query-parameters"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters"},"#")],-1),Ge=s("Supports all "),Ye=s("global query parameters"),Me=s("."),Pe=e("h3",{id:"returns"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns"},"#")],-1),Ke=s("An array of up to "),He=s("limit"),Je=s(),We=e("a",{href:"#the-file-object"},"file objects",-1),Le=s(". If no items are available, data will be an empty array."),Ne={class:"right"},Ve=e("h3",{id:"rest-api"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api"},"#")],-1),ze=e("pre",null,[e("code",null,`GET /files
SEARCH /files
`)],-1),Xe=s("Learn more about SEARCH ->"),Ze=e("h3",{id:"graphql"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql"},"#")],-1),$e=e("pre",null,[e("code",null,`POST /graphql/system
`)],-1),es=e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Query"),s(` {
	files: [directus_files]
}
`)])],-1),ss=e("h5",{id:"example-2"},[s("Example "),e("a",{class:"header-anchor",href:"#example-2"},"#")],-1),ls=e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"query"),s(` {
	files {
		id
		filename_disk
	}
}
`)])],-1),ts=e("hr",null,null,-1),as=e("h2",{id:"retrieve-a-file"},[s("Retrieve a File "),e("a",{class:"header-anchor",href:"#retrieve-a-file"},"#")],-1),ns=e("p",null,"Retrieve a single file by primary key.",-1),os={class:"two-up"},is={class:"left"},rs=e("h3",{id:"query-parameters-2"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-2"},"#")],-1),cs=s("Supports all "),hs=s("global query parameters"),ds=s("."),us=e("h3",{id:"returns-2"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-2"},"#")],-1),ps=e("p",null,[s("Returns a "),e("a",{href:"#the-file-object"},"file object"),s(" if a valid primary key was provided.")],-1),fs=e("div",{class:"right"},[e("h3",{id:"rest-api-2"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-2"},"#")]),e("pre",null,[e("code",null,`GET /files/:id
`)]),e("h5",{id:"example-3"},[s("Example "),e("a",{class:"header-anchor",href:"#example-3"},"#")]),e("pre",null,[e("code",null,`GET /files/0fca80c4-d61c-4404-9fd7-6ba86b64154d
`)]),e("h3",{id:"graphql-2"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-2"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Query"),s(` {
	files_by_id(id:`),e("span",{class:"hljs-literal"}," ID"),s(`!): directus_files
}
`)])]),e("h5",{id:"example-4"},[s("Example "),e("a",{class:"header-anchor",href:"#example-4"},"#")]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"query"),s(` {
	files_by_id(id: `),e("span",{class:"hljs-string"},'"0fca80c4-d61c-4404-9fd7-6ba86b64154d"'),s(`) {
		id
		filename_disk
	}
}
`)])])],-1),_s=e("h2",{id:"upload-a-file"},[s("Upload a File "),e("a",{class:"header-anchor",href:"#upload-a-file"},"#")],-1),gs=e("p",null,"Upload/create a new file.",-1),ms={class:"two-up"},ys={class:"left"},js=e("p",null,[s("To upload a file, use "),e("code",null,"multipart/form-data"),s(" as the encoding type, instead of JSON.")],-1),bs=e("p",null,[s("The file contents has to be provided in a part called "),e("code",null,"file"),s(". All other properties of "),e("a",{href:"#the-file-object"},"the file object"),s(" can be provided as parts as well.")],-1),As=e("div",{class:"tip hint"},[e("div",{class:"hint-title"},"Order Matters"),e("p",null,[s("Make sure to define the non-file properties "),e("em",null,"first"),s(". This ensures that the file metadata is associated with the correct file.")])],-1),qs=e("p",null,"You can upload multiple files at a time by repeating the payload with different contents, for example:",-1),xs=e("pre",null,[e("code",null,`--__X_BOUNDARY__
Content-Disposition: form-data; name="title"

Example
--__X_BOUNDARY__
Content-Disposition: form-data; name="file"; filename="paulo-silva-vSRgXtQuns8-unsplash.jpg"
Content-Type: image/jpeg

// binary data

--__X_BOUNDARY__
Content-Disposition: form-data; name="title"

Another Title
--__X_BOUNDARY__
Content-Disposition: form-data; name="file"; filename="mae-mu-GFhqNX1gE9E-unsplash.jpg"
Content-Type: image/jpeg

// binary data
`)],-1),ws=e("p",null,[s("In JavaScript, this can be achieved using the native "),e("code",null,"FormData"),s(" class:")],-1),Rs=e("pre",null,[e("code",{class:"language-js"},[e("span",{class:"hljs-keyword"},"import"),s(" axios "),e("span",{class:"hljs-keyword"},"from"),s(),e("span",{class:"hljs-string"},"'axios'"),s(`;

`),e("span",{class:"hljs-keyword"},"const"),s(" fileInput = "),e("span",{class:"hljs-built_in"},"document"),s(".querySelector("),e("span",{class:"hljs-string"},`'input[type="file"]'`),s(`);
`),e("span",{class:"hljs-keyword"},"const"),s(" formData = "),e("span",{class:"hljs-keyword"},"new"),s(` FormData();

formData.append(`),e("span",{class:"hljs-string"},"'title'"),s(", "),e("span",{class:"hljs-string"},"'My First File'"),s(`);
formData.append(`),e("span",{class:"hljs-string"},"'file'"),s(", fileInput.files["),e("span",{class:"hljs-number"},"0"),s(`]);

`),e("span",{class:"hljs-keyword"},"await"),s(" axios.post("),e("span",{class:"hljs-string"},"'/files'"),s(`, formData);
`)])],-1),Ts=e("h3",{id:"query-parameters-3"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-3"},"#")],-1),vs=s("Supports all "),Us=s("global query parameters"),ks=s("."),Bs=e("h3",{id:"returns-3"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-3"},"#")],-1),Es=e("p",null,[s("Returns the "),e("a",{href:"#the-file-object"},"file object"),s(" for the uploaded file, or an array of "),e("a",{href:"#the-file-object"},"file objects"),s(" if multiple files were uploaded at once.")],-1),Is=e("div",{class:"right"},[e("pre",null,[e("code",null,`POST /files
`)]),e("pre",null,[e("code",null,`// Request

Content-Type: multipart/form-data; charset=utf-8; boundary=__X_BOUNDARY__
Content-Length: 3442422

--__X_BOUNDARY__
Content-Disposition: form-data; name="file"; filename="paulo-silva-vSRgXtQuns8-unsplash.jpg"
Content-Type: image/jpeg

\xFF\xD8\xFF\xE0JFIFHH\xFF\xE2ICC_PROFILE\flcmsmntrRGB XYZ \x07\xDC)9acspAPPL\xF6\xD6\xD3-lcms
desc\xFC^cprt\\\vwtpthbkpt|rXYZ\x90gXYZ\xA4bXYZ\xB8rTRC\xCC@gTRC\xCC@bTRC\xCC@descc2textIXXYZ \xF6\xD6\xD3-XYZ 3\xA4XYZ o\xA28\xF5\x90XYZ b\x99\xB7\x85\xDAXYZ $\xA0\x84\xB6\xCFcurv\xCB\xC9c\x92\bk\v\xF6?Q4!\xF1)\x902;\x92FQw]\xEDkpz\x89\xB1\x9A|\xACi\xBF}\xD3\xC3\xE90\xFF\xFF\xFF\xDB\x84\b\b\x07\x07
`)])],-1),Qs=e("hr",null,null,-1),Ss=e("h2",{id:"import-a-file"},[s("Import a File "),e("a",{class:"header-anchor",href:"#import-a-file"},"#")],-1),Ds=e("p",null,"Import a file from the web",-1),Fs={class:"two-up"},Os={class:"left"},Cs=e("h3",{id:"query-parameters-4"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-4"},"#")],-1),Gs=s("Supports all "),Ys=s("global query parameters"),Ms=s("."),Ps=e("h3",{id:"request-body"},[s("Request Body "),e("a",{class:"header-anchor",href:"#request-body"},"#")],-1),Ks=e("div",{class:"definitions"},[e("p",null,[e("code",null,"url"),s(),e("strong",null,"Required"),e("br"),s(" The URL to download the file from.")]),e("p",null,[e("code",null,"data"),e("br"),s(" Any of "),e("a",{href:"#the-file-object"},"the file object"),s("\u2019s properties.")])],-1),Hs=e("h3",{id:"returns-4"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-4"},"#")],-1),Js=e("p",null,[s("Returns the "),e("a",{href:"#the-file-object"},"file object"),s(" for the imported file.")],-1),Ws=e("div",{class:"right"},[e("h3",{id:"rest-api-3"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-3"},"#")]),e("pre",null,[e("code",null,`POST /files/import
`)]),e("h5",{id:"example-5"},[s("Example "),e("a",{class:"header-anchor",href:"#example-5"},"#")]),e("pre",null,[e("code",{class:"language-json"},[e("span",{class:"hljs-comment"},"// POST /files/import"),s(`

{
	`),e("span",{class:"hljs-attr"},'"url"'),s(": "),e("span",{class:"hljs-string"},'"https://source.unsplash.com/random"'),s(`,
	`),e("span",{class:"hljs-attr"},'"data"'),s(`: {
		`),e("span",{class:"hljs-attr"},'"title"'),s(": "),e("span",{class:"hljs-string"},'"Example"'),s(`
	}
}
`)])]),e("h3",{id:"graphql-3"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-3"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Mutation"),s(` {
	import_file(url:`),e("span",{class:"hljs-type"}," String"),s(`!, data: create_directus_files_input!): directus_files
}
`)])]),e("h5",{id:"example-6"},[s("Example "),e("a",{class:"header-anchor",href:"#example-6"},"#")]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"mutation"),s(` {
	import_file(url: `),e("span",{class:"hljs-string"},'"https://source.unsplash.com/random"'),s(", data: { title: "),e("span",{class:"hljs-string"},'"Example"'),s(` }) {
		id
	}
}
`)])])],-1),Ls=e("hr",null,null,-1),Ns=e("h2",{id:"update-a-file"},[s("Update a File "),e("a",{class:"header-anchor",href:"#update-a-file"},"#")],-1),Vs=e("p",null,"Update an existing file, and/or replace it\u2019s file contents.",-1),zs={class:"two-up"},Xs={class:"left"},Zs=e("h3",{id:"query-parameters-5"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-5"},"#")],-1),$s=s("Supports all "),el=s("global query parameters"),sl=s("."),ll=e("h3",{id:"request-body-2"},[s("Request Body "),e("a",{class:"header-anchor",href:"#request-body-2"},"#")],-1),tl=e("p",null,[s("You can either submit a JSON object consisting of a partial "),e("a",{href:"#the-file-object"},"file object"),s(" to update the file meta, or send a multipart/form-data request to replace the file contents on disk. See "),e("a",{href:"#upload-a-file"},"Upload a File"),s(" for more information on the structure of this "),e("code",null,"multipart/form-data"),s(" request.")],-1),al=e("h3",{id:"returns-5"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-5"},"#")],-1),nl=e("p",null,[s("Returns the "),e("a",{href:"#the-file-object"},"file object"),s(" for the updated file.")],-1),ol=e("div",{class:"right"},[e("h3",{id:"rest-api-4"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-4"},"#")]),e("pre",null,[e("code",null,`PATCH /files/:id
`)]),e("h5",{id:"example-7"},[s("Example "),e("a",{class:"header-anchor",href:"#example-7"},"#")]),e("pre",null,[e("code",{class:"language-json"},[e("span",{class:"hljs-comment"},"// PATCH /files/0fca80c4-d61c-4404-9fd7-6ba86b64154d"),s(`

{
	`),e("span",{class:"hljs-attr"},'"title"'),s(": "),e("span",{class:"hljs-string"},'"Example"'),s(`
}
`)])]),e("h3",{id:"graphql-4"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-4"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Mutation"),s(` {
	update_files_item(id:`),e("span",{class:"hljs-literal"}," ID"),s(`!, data: update_directus_files_input!): directus_files
}
`)])]),e("h5",{id:"example-8"},[s("Example "),e("a",{class:"header-anchor",href:"#example-8"},"#")]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"mutation"),s(` {
	update_files_item(id: `),e("span",{class:"hljs-string"},'"0fca80c4-d61c-4404-9fd7-6ba86b64154d"'),s(", data: { title: "),e("span",{class:"hljs-string"},'"Example"'),s(` }) {
		id
		title
	}
}
`)])])],-1),il=e("hr",null,null,-1),rl=e("h2",{id:"update-multiple-files"},[s("Update Multiple Files "),e("a",{class:"header-anchor",href:"#update-multiple-files"},"#")],-1),cl=e("p",null,"Update multiple files at the same time.",-1),hl={class:"two-up"},dl={class:"left"},ul=e("h3",{id:"query-parameters-6"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-6"},"#")],-1),pl=s("Supports all "),fl=s("global query parameters"),_l=s("."),gl=e("h3",{id:"request-body-3"},[s("Request Body "),e("a",{class:"header-anchor",href:"#request-body-3"},"#")],-1),ml=e("div",{class:"definitions"},[e("p",null,[e("code",null,"keys"),s(),e("strong",null,"Required"),e("br"),s(" Array of primary keys of the files you\u2019d like to update.")]),e("p",null,[e("code",null,"data"),s(),e("strong",null,"Required"),e("br"),s(" Any of "),e("a",{href:"#the-file-object"},"the file object"),s("\u2019s properties.")])],-1),yl=e("h3",{id:"returns-6"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-6"},"#")],-1),jl=e("p",null,[s("Returns the "),e("a",{href:"#the-file-object"},"file objects"),s(" for the updated files.")],-1),bl=e("div",{class:"right"},[e("h3",{id:"rest-api-5"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-5"},"#")]),e("pre",null,[e("code",null,`PATCH /files
`)]),e("h5",{id:"example-9"},[s("Example "),e("a",{class:"header-anchor",href:"#example-9"},"#")]),e("pre",null,[e("code",{class:"language-json"},[e("span",{class:"hljs-comment"},"// PATCH /files"),s(`

{
	`),e("span",{class:"hljs-attr"},'"keys"'),s(": ["),e("span",{class:"hljs-string"},'"b6123925-2fc0-4a30-9d86-863eafc0a6e7"'),s(", "),e("span",{class:"hljs-string"},'"d17c10aa-0bad-4864-9296-84f522c753e5"'),s(`],
	`),e("span",{class:"hljs-attr"},'"data"'),s(`: {
		`),e("span",{class:"hljs-attr"},'"tags"'),s(": ["),e("span",{class:"hljs-string"},'"cities"'),s(`]
	}
}
`)])]),e("h3",{id:"graphql-5"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-5"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Mutation"),s(` {
	update_files_items(ids: `),e("span",{class:"hljs-literal"},"[ID"),s(`!]!, data: update_directus_files!): [directus_files]
}
`)])]),e("h5",{id:"example-10"},[s("Example "),e("a",{class:"header-anchor",href:"#example-10"},"#")]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"mutation"),s(` {
	update_files_items(
		ids: [`),e("span",{class:"hljs-string"},'"b6123925-2fc0-4a30-9d86-863eafc0a6e7"'),s(", "),e("span",{class:"hljs-string"},'"d17c10aa-0bad-4864-9296-84f522c753e5"'),s(`]
		data: { tags: [`),e("span",{class:"hljs-string"},'"cities"'),s(`] }
	)
}
`)])])],-1),Al=e("hr",null,null,-1),ql=e("h2",{id:"delete-a-file"},[s("Delete a File "),e("a",{class:"header-anchor",href:"#delete-a-file"},"#")],-1),xl=e("p",null,"Delete an existing file.",-1),wl={class:"two-up"},Rl={class:"left"},Tl=e("div",{class:"danger hint"},[e("div",{class:"hint-title"},"Destructive"),e("p",null,"This will also delete the file from disk.")],-1),vl=e("h3",{id:"query-parameters-7"},[s("Query Parameters "),e("a",{class:"header-anchor",href:"#query-parameters-7"},"#")],-1),Ul=s("Supports all "),kl=s("global query parameters"),Bl=s("."),El=e("h3",{id:"returns-7"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-7"},"#")],-1),Il=e("p",null,"Empty response.",-1),Ql=e("div",{class:"right"},[e("h3",{id:"rest-api-6"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-6"},"#")]),e("pre",null,[e("code",null,`DELETE /files/:id
`)]),e("h5",{id:"example-11"},[s("Example "),e("a",{class:"header-anchor",href:"#example-11"},"#")]),e("pre",null,[e("code",null,`DELETE /files/0fca80c4-d61c-4404-9fd7-6ba86b64154d
`)]),e("h3",{id:"graphql-6"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-6"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Mutation"),s(` {
	delete_files_item(id:`),e("span",{class:"hljs-literal"}," ID"),s(`!): delete_one
}
`)])]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"mutation"),s(` {
	delete_files_item(id: `),e("span",{class:"hljs-string"},'"0fca80c4-d61c-4404-9fd7-6ba86b64154d"'),s(`) {
		id
	}
}
`)])])],-1),Sl=e("hr",null,null,-1),Dl=e("h2",{id:"delete-multiple-files"},[s("Delete Multiple Files "),e("a",{class:"header-anchor",href:"#delete-multiple-files"},"#")],-1),Fl=e("p",null,"Delete multiple files at once.",-1),Ol=e("div",{class:"two-up"},[e("div",{class:"left"},[e("div",{class:"danger hint"},[e("div",{class:"hint-title"},"Destructive"),e("p",null,"This will also delete the files from disk.")]),e("h3",{id:"request-body-4"},[s("Request Body "),e("a",{class:"header-anchor",href:"#request-body-4"},"#")]),e("p",null,"Array of file primary keys"),e("h3",{id:"returns-8"},[s("Returns "),e("a",{class:"header-anchor",href:"#returns-8"},"#")]),e("p",null,"Empty response.")]),e("div",{class:"right"},[e("h3",{id:"rest-api-7"},[s("REST API "),e("a",{class:"header-anchor",href:"#rest-api-7"},"#")]),e("pre",null,[e("code",null,`DELETE /files
`)]),e("h5",{id:"example-12"},[s("Example "),e("a",{class:"header-anchor",href:"#example-12"},"#")]),e("pre",null,[e("code",{class:"language-json"},[e("span",{class:"hljs-comment"},"// DELETE /files"),s(`

[`),e("span",{class:"hljs-string"},'"d17c10aa-0bad-4864-9296-84f522c753e5"'),s(", "),e("span",{class:"hljs-string"},'"b6123925-2fc0-4a30-9d86-863eafc0a6e7"'),s(`]
`)])]),e("h3",{id:"graphql-7"},[s("GraphQL "),e("a",{class:"header-anchor",href:"#graphql-7"},"#")]),e("pre",null,[e("code",null,`POST /graphql/system
`)]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"type"),e("span",{class:"hljs-type"}," Mutation"),s(` {
	delete_files_items(ids: `),e("span",{class:"hljs-literal"},"[ID"),s(`!]!): delete_many
}
`)])]),e("h5",{id:"example-13"},[s("Example "),e("a",{class:"header-anchor",href:"#example-13"},"#")]),e("pre",null,[e("code",{class:"language-graphql"},[e("span",{class:"hljs-keyword"},"mutation"),s(` {
	delete_files_items(ids: [`),e("span",{class:"hljs-string"},'"d17c10aa-0bad-4864-9296-84f522c753e5"'),s(", "),e("span",{class:"hljs-string"},'"b6123925-2fc0-4a30-9d86-863eafc0a6e7"'),s(`]) {
		ids
	}
}
`)])])])],-1),Pl={setup(Cl,{expose:i}){const n={title:"Accessing Files",modularExtension:!1,pageClass:"page-reference"};return i({frontmatter:n}),(Gl,Yl)=>{const t=o("router-link"),r=o("DocsWrapper");return c(),h(r,{frontmatter:n},{default:l(()=>[e("div",g,[m,y,j,b,A,q,x,w,R,e("div",T,[e("div",v,[U,k,e("ul",null,[e("li",null,[B,E,I,Q,a(t,{to:"/docs/configuration/project-settings/#files-thumbnails"},{default:l(()=>[S]),_:1}),D])]),F,O,C,G,Y,M,P,K]),H]),J,W,e("div",L,[e("div",N,[e("div",V,[z,X,Z,$,ee,se,e("p",null,[le,te,ae,ne,oe,a(t,{to:"/docs/reference/system/folders/"},{default:l(()=>[ie]),_:1}),re]),e("p",null,[ce,he,de,ue,pe,a(t,{to:"/docs/reference/system/users/"},{default:l(()=>[fe]),_:1}),_e]),ge,e("p",null,[me,ye,je,be,Ae,a(t,{to:"/docs/reference/system/users/"},{default:l(()=>[qe]),_:1}),xe]),we,Re,Te,ve,Ue,ke,Be,Ee])]),Ie]),Qe,Se,De,e("div",Fe,[e("div",Oe,[Ce,e("p",null,[Ge,a(t,{to:"/docs/reference/query"},{default:l(()=>[Ye]),_:1}),Me]),Pe,e("p",null,[Ke,a(t,{to:"/docs/reference/query/#limit"},{default:l(()=>[He]),_:1}),Je,We,Le])]),e("div",Ne,[Ve,ze,e("p",null,[a(t,{to:"/docs/reference/introduction/#search-http-method"},{default:l(()=>[Xe]),_:1})]),Ze,$e,es,ss,ls])]),ts,as,ns,e("div",os,[e("div",is,[rs,e("p",null,[cs,a(t,{to:"/docs/reference/query"},{default:l(()=>[hs]),_:1}),ds]),us,ps]),fs]),_s,gs,e("div",ms,[e("div",ys,[js,bs,As,qs,xs,ws,Rs,Ts,e("p",null,[vs,a(t,{to:"/docs/reference/query"},{default:l(()=>[Us]),_:1}),ks]),Bs,Es]),Is]),Qs,Ss,Ds,e("div",Fs,[e("div",Os,[Cs,e("p",null,[Gs,a(t,{to:"/docs/reference/query"},{default:l(()=>[Ys]),_:1}),Ms]),Ps,Ks,Hs,Js]),Ws]),Ls,Ns,Vs,e("div",zs,[e("div",Xs,[Zs,e("p",null,[$s,a(t,{to:"/docs/reference/query"},{default:l(()=>[el]),_:1}),sl]),ll,tl,al,nl]),ol]),il,rl,cl,e("div",hl,[e("div",dl,[ul,e("p",null,[pl,a(t,{to:"/docs/reference/query"},{default:l(()=>[fl]),_:1}),_l]),gl,ml,yl,jl]),bl]),Al,ql,xl,e("div",wl,[e("div",Rl,[Tl,vl,e("p",null,[Ul,a(t,{to:"/docs/reference/query"},{default:l(()=>[kl]),_:1}),Bl]),El,Il]),Ql]),Sl,Dl,Fl,Ol])]),_:1})}}};export{Pl as default};
