Add File
To add a file with the bArchive API, utilize the addFile
method from the SDK.
Sample Code Snippet
Here is a JavaScript code snippet demonstrating the use of the addFile
method:
import { Barchive, Network } from 'edeXa-sdk';
async function addFile() {
const barchive = new Barchive({
...settings,
authorization: `Bearer ${token}`,
});
const settings = {
network: Network.SANDBOX, // or Network.MAINNET for the mainnet network
};
const dataToAddFile = {
lat: '72.12',
long: '72.12',
expireTimeInMinutes: '2',
description: 'write description whatever you write',
attachments: 'IMAGE_URL' // https://picsum.photos/200
}
try {
const addedFileResponse = await barchive.addFile(dataToAddFile);
// Handle success
} catch (error) {
// Handle error
}
}
Key Points to Note
- Asynchronous Function: The
addFile
function is an asynchronous (async
) function, utilizingawait
to halt execution until thebarchive.addFile
promise is fulfilled. Upon successful resolution, the response for adding the file is logged. Conversely, should an error arise, it's captured and recorded usingconsole.error
. - Token Substitution: It's crucial to replace the
token
in theAuthorization
header with your personaltoken
, which will be provided as a response to the authentication method. - Attachments Handling: Ensure to substitute
IMAGE_URL
with your actualattachments
value. Additionally, it's possible to include multiple files within theattachments
field. - Geolocation Information: Input the latitude and longitude values in the
lat
andlong
fields, correspondingly. - File Description: Incorporate an accurate file
description
within thedescription
field. - Expiration Timing: Designate the file's expiration period in the
expireTimeInMinutes
field, detailing how long the file should remain accessible before expiring.
Request Parameters
Parameter | Required | Type | Description |
---|---|---|---|
authorization | Yes | String | Enter your authentication token |
lat | Yes | Number | Enter the latitude value |
long | Yes | Number | Enter the longitude value |
expireTimeInMinutes | Yes | Number | Enter the file's expiration period |
description | Yes | String | Enter a description for the file |
attachments | Yes | String | Enter a attachment for the file |
Response Format
Key | Type | Description |
---|---|---|
id | String | A unique identifier |
file | Array | An array of file objects |
fileName | String | The name of the file |
description | String | The description of the file |
lat | String | Latitude of the file |
long | String | Longitude of the file |
transactionId | String | The transaction ID |
uniqueId | String | The unique ID |
expireTime | String | The expiration time |
expireTimeStamp | String | The expiration timestamp |
createdAt | String | The creation time |
updatedAt | String | The update time |
Response Format of File Object
Key | Type | Description |
---|---|---|
fileName | String | The name of the file |
fileType | String | The type of the file |
mimeType | String | The mime type of the file |
fileSize | Number | The file size |