Skip to content

Commit

Permalink
Fetch File from IPFS API
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhalevedant06 committed Dec 3, 2022
1 parent d147e73 commit e84396b
Show file tree
Hide file tree
Showing 7 changed files with 1,558 additions and 11 deletions.
Binary file added server/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions server/controllers/book.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const Moralis = dp.default;
import Book from '../models/book.model.js';
import mongoose from 'mongoose';
import fs from "fs"
import {client} from '../utils/ipfs-client.js'
import axios from "axios"

export const fileUploadController = async (req, res) => {
const {title,description,DBCoins,Ether,author,genre,pageCount} = req.body;
const { filename } = req.file;
Expand Down Expand Up @@ -48,3 +51,29 @@ export const fileUploadController = async (req, res) => {
console.log(error);
}
};

export const getBookFromIPFS = async(req,res)=>{
const {ipfsLink} = req.body;
const response = await axios.get(ipfsLink, {responseType: "arraybuffer"} )
res.send({buffer:response.data})
// fs.appendFileSync('./out/file.pdf', Buffer.from(response.data));
}

export const getAllBooks = async(req,res)=>{
try {
const data = await Book.find();
res.status(200).send(data);
} catch (error) {
console.log(error);
}
}

export const getBookData = async(req,res)=>{
const {ID} = req.params
try {
const data = await Book.findOne({_id:ID});
res.status(200).send(data);
} catch (error) {
console.log(error);
}
}
Loading

0 comments on commit e84396b

Please sign in to comment.