Edge Storage API
The Edge Functions Storage API is an interface that allows access to the Edge Storage. Through this interface, it’s possible to read and write data in the storage and its buckets.
Class instantiation
Section titled Class instantiationTo leverage this API, you need to import and instantiate the Storage
class, passing the bucket’s name.
Syntax
Section titled SyntaxImport:
Instantiate:
Parameters
Section titled ParametersParameter | Type | Description |
---|---|---|
bucket | string | Name of a bucket. |
Return value
Section titled Return valueStorage object used to access Edge Storage.
Methods
Section titled Methodsasync storage.put
Section titled async storage.putThe Storage.put
method is used to insert a new object into the storage.
Syntax
Section titled SyntaxParameters
Section titled ParametersParameter | Type | Description |
---|---|---|
key | string | Identifier that allows the search for an object in the storage |
value | ArrayBuffer ou ReadableStream | Content of the object being stored. In case value implements a ReadableStream, the Stream APIs can be used, and the option content-lenght is required |
options | object | The options attributes are described in the table below |
options
To pass the options
parameter, you must provide an object with the following attributes:
Attribute | Type | Description |
---|---|---|
content-type | string | The content-type of the object being created. It’s similar to the HTTP Header content-type and describes how the content of the bucket should be treated. content-type is optional. The default value is application/octet-stream |
content-length | string | The size of the object to be created, in bytes. It’s mandatory when the value is ReadableStream |
metadata | object | Any JavaScript object containing information about the object that will be stored in the Storage. All properties of the object must be strings |
Return
Section titled ReturnSuccess | Error |
---|---|
No response | Throws a StorageError |
Code sample
Section titled Code sample- To persist the request body:
- To persist a JSON object:
- To save a JSON with metadata:
async storage.get(key)
Section titled async storage.get(key)The storage.get(key)
method is used to retrieve an object.
Syntax
Section titled SyntaxParameters
Section titled ParametersParameter | Type | Description |
---|---|---|
key | string | Identifier that allows the search for an object in the bucket |
Return
Section titled ReturnSuccess | Error |
---|---|
Returns an object of the class StorageObject | Throws a StorageError |
Code sample
Section titled Code sample- To retrieve and return content from the storage:
- To get a JSON from the storage:
- To read an object’s metadata:
async storage.delete(key)
Section titled async storage.delete(key)The Storage.delete(key)
is used to remove an object from Edge Storage.
Syntax
Section titled SyntaxParameters
Section titled ParametersParameter | Type | Description |
---|---|---|
key | string | Identifier that allows the search for an object in the bucket |
Return
Section titled ReturnSuccess | Error |
---|---|
No response | Throws a StorageError |
Code sample
Section titled Code sample- To remove an object stored in Edge Storage related to a specific
bucket
:
async storage.list()
Section titled async storage.list()The Storage.list()
method is used to list all objects belonging to the specific bucket
.
Syntax
Section titled SyntaxReturn
Section titled ReturnSuccess | Error |
---|---|
Returns an object of the class StorageObjectList | It throws a StorageError |
Code sample
Section titled Code sample- Listing objects from Azion Storage:
StorageObject Class Methods
Section titled StorageObject Class MethodsMethod | Description |
---|---|
StorageObject.content | Read-only property containing a ReadableStream for the content stored in the storage |
async StorageObject.arrayBuffer() | Asynchronous function that returns an ArrayBuffer with the content stored in the storage. This method consumes the ReadableStream from the content property |
StorageObject.metadata | Read-only property containing a Map object with the metadata of the object stored in the storage |
StorageObject.contentType | Read-only property containing the content-type of the content stored in the storage |
StorageObject.contentLength | Read-only property containing the size in bytes of the content stored in the storage |