Learn how to upload files on JigsawStack File Storage
The file upload method is ideal for files that are not larger than 100MB.
The File Storage will assume the content type of an asset automatically. However, you can specify specific file content types like image/jpeg, image/png, e.t.c
import{JigsawStack}from"jigsawstack";const publicKey ="your-public-key";const jigsawstack =JigsawStack({apiKey:"your-api-key",});const imageFile = fs.readFileSync("./beach_house.png");const result =await jigsawstack.store.upload(imageFile,{filename:"beach_house.png",});// Attach your public key to make your uploaded file accessibleconst publicFileUrl =`${result.url}?x-api-key=${publicKey}`;
When uploading a file with a filename that already exists, the default behavior is to return a 400 file already exists error. If you want to overwrite a file that already exists, set overwrite to true
import{JigsawStack}from"jigsawstack";const publicKey ="your-public-key";const jigsawstack =JigsawStack({apiKey:"your-api-key",});const imageFile = fs.readFileSync("./beach_house.png");const result =await jigsawstack.store.upload(imageFile,{filename:"beach_house.png",overwrite:true,});// Attach your public key to make your uploaded file accessibleconst publicFileUrl =`${result.url}?x-api-key=${publicKey}`;
By default, the File Storage will assume the content type of an asset automatically. If you want to specify the content type for your asset simply pass the contentType option during upload.
You can use an uploaded file across other JigsawStack APIs by using the file key and attaching the value to the file_store_key parameter on any API that supports it.
import{JigsawStack}from"jigsawstack";const jigsawstack =JigsawStack({apiKey:"your-api-key",});const imageFile = fs.readFileSync("./beach_house.png");// Upload the imageconst result =await jigsawstack.store.upload(imageFile,{filename:"beach_house.png",overwrite:true,content_type:"image/png",});// Retrieve the file key.const fileKey = result.key// Use the file keyconst result =await jigsawstack.vision.vocr({prompt:"Describe the image in detail"file_store_key: fileKey // file key is used here});