Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@vercel/blob
Advanced tools
The Vercel Blob JavaScript API client.
npm install @vercel/blob
import * as vercelBlob from '@vercel/blob';
// usage
async function someMethod() {
const blob = await vercelBlob.put(
'profilesv1/user-12345.txt', // pathname for the blob
'Hello World!', // body
{ access: 'public' }, // mandatory options
);
console.log(blob.url);
// https://public.blob.vercel-storage.com/n1g9m63etib6gkcjqjpspsiwe7ea/profilesv1/user-12345-NoOVGDVcqSPc7VYCUAGnTzLTG2qEM2.txt
}
put(pathname, body, options)
Upload a blob to the Vercel Blob API, and returns the URL of the blob.
async function put(
pathname: string,
body: ReadableStream | String | ArrayBuffer | Blob // All fetch body types are supported: https://developer.mozilla.org/en-US/docs/Web/API/fetch#body
options: {
access: 'public', // mandatory, as we will provide private blobs in the future
contentType?: string, // inferred from pathname
contentEncoding?: string, // text based files are gzipped by default when possible
cacheControl?: string, // default to 1 year
// `token` defaults to process.env.BLOB_STORE_WRITE_TOKEN on Vercel
// and can be configured when you connect more stores to a project
// or using Vercel Blob outside of Vercel
token?: string,
}): Promise<{url: string}> {}
Delete a blob by its full URL. Will throw if the blob does not exist.
async function del(
url: string,
options?: {
token?: string;
},
): Promise<void> {}
Get the metadata of a blob by its full URL.
async function head(
url: string,
options?: {
token?: string;
},
): Promise<{
size: number;
uploadedAt: Date;
pathname: string;
contentType: string;
contentDisposition: string;
contentEncoding?: string;
cacheControl?: string;
}> {}
This example shows a form uploading a file to the Vercel Blob API.
// /app/UploadForm.tsx
'use client';
import type { PutBlobResult } from '@vercel/blob';
import { useState } from 'react';
export default function UploadForm() {
const [blob, setBlob] = useState<PutBlobResult | null>(null);
return (
<>
<form
action="/api/upload"
method="POST"
encType="multipart/form-data"
onSubmit={async (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const response = await fetch('/api/upload', {
method: 'POST',
body: formData,
});
const blob = (await response.json()) as PutBlobResult;
setBlob(blob);
}}
>
<input type="file" name="file" />
<button type="submit">Upload</button>
</form>
{blob && (
<div>
Blob url: <a href={blob.url}>{blob.url}</a>
</div>
)}
</>
);
}
// /app/api/upload/route.ts
import * as vercelBlob from '@vercel/blob';
import { NextResponse } from 'next/server';
export async function POST(request: Request) {
const form = await request.formData();
const file = form.get('file') as File;
if (!file) {
return NextResponse.json(
{ message: 'No file to upload.' },
{ status: 400 },
);
}
const blob = await vercelBlob.put(file.name, file, { access: 'public' });
return NextResponse.json(blob);
}
FAQs
The Vercel Blob JavaScript API client
We found that @vercel/blob demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.