Skip to main content

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, utilizing await to halt execution until the barchive.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 using console.error.
  • Token Substitution: It's crucial to replace the token in the Authorization header with your personal token, which will be provided as a response to the authentication method.
  • Attachments Handling: Ensure to substitute IMAGE_URL with your actual attachments value. Additionally, it's possible to include multiple files within the attachments field.
  • Geolocation Information: Input the latitude and longitude values in the lat and long fields, correspondingly.
  • File Description: Incorporate an accurate file description within the description 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

ParameterRequiredTypeDescription
authorizationYesStringEnter your authentication token
latYesNumberEnter the latitude value
longYesNumberEnter the longitude value
expireTimeInMinutesYesNumberEnter the file's expiration period
descriptionYesStringEnter a description for the file
attachmentsYesStringEnter a attachment for the file

Response Format

KeyTypeDescription
idStringA unique identifier
fileArrayAn array of file objects
fileNameStringThe name of the file
descriptionStringThe description of the file
latStringLatitude of the file
longStringLongitude of the file
transactionIdStringThe transaction ID
uniqueIdStringThe unique ID
expireTimeStringThe expiration time
expireTimeStampStringThe expiration timestamp
createdAtStringThe creation time
updatedAtStringThe update time

Response Format of File Object

KeyTypeDescription
fileNameStringThe name of the file
fileTypeStringThe type of the file
mimeTypeStringThe mime type of the file
fileSizeNumberThe file size