I'm using pinata and trying to pin some files to ipfs. These files are coming from user input and not readed from the fs. Having this code:
export const deployFile = async (
file: Express.Multer.File,
httpService: HttpService,
): Promise<string> => {
const formData = new FormData();
formData.append('file', Readable.from(file.buffer));
try {
const observable = httpService
.post(process.env.PINATA_BASE_URL + '/pinning/pinFileToIPFS', formData, {
headers: {
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
pinata_api_key: process.env.PINATA_API_KEY,
pinata_secret_api_key: process.env.PINATA_API_SECRET_KEY,
},
})
.pipe(map((response) => response.data));
const response = await lastValueFrom(observable);
return response.IpfsHash;
} catch (error) {
logger.error(`Error deploying image reason: ${error.response.data.error}`);
}
Always hitting error Invalid request format.
. How ever if file is readed from the fs using:
const formData = new FormData();
formData.append('file', createReadStream(join(process.cwd(), '/images/1.jpeg')));
Everything work as expected and file is successfully pinned on Pinata. So i'm thinking:
Readable.from(file.buffer)
is different than createReadStream(join(process.cwd(), '/images/1.jpeg'))
Any idea how to deploy user files directly to ipfs and not reading them from FS?