In replit I have made all the files. I am using Cloudinary to generate the URL of two images which is be to sent in the cloud API (those two images will generate a new image URL) which we will access with a get request. As this API is hosted in AWS I cannot disclose it. I have used node js to fetch the URL in $@#%%/API to process the image in the cloud and it takes 40 seconds to complete and return success. The cloud contains a GAN model which generates a new image and saves the result as style.png in @##@%/result/. My code looks like this: This shows segmentation fault as soon as I select the image. Can anyone show or guide why this is occurring.
const Formidable = require("formidable");
var cloudinary = require("cloudinary").v2;
const fs = require("fs");
const express = require("express");
const path = require('path');
// mod.cjs
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
// async function loadMyfetcher() {
// const fetch = import("node-fetch");
// // import fetch from 'node-fetch'
// }
// loadMyfetcher();
const FormData = require('form-data');
require("dotenv").config();
// Cloudinary configuration settings
// This will be fetched from the .env file in the root directory
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET,
});
const port = process.env.PORT || 8080;
const app = express();
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')))
//Create a server
app.get("/", (req, res) => {
const obj = {
latestprod0imagelink: "images/banner.png",
prod0head: "dress sale product on",
prod0details: "sale is on for dress",
prod0color: "black",
latestprod1imagelink: "images/pic31.jpeg",
prod1head: "sale biggest sale",
prod1details: "biggest lakme cream",
prod1color: "black",
latestprod2imagelink: "images/banner.jpg",
prod2head: "p2 head",
prod2details: "p2 details",
prod2color: "white"
};
res.render("index", obj);
});
app.get("/pd.html", (req, res) => {
const indexdata = fs.readFileSync("frontend/templates/pd.html");
res.send(indexdata.toString());
});
app.get("/pd1.html", (req, res) => {
const indexdata = fs.readFileSync("frontend/templates/pd1.html");
res.send(indexdata.toString());
});
app.get("/pd2.html", (req, res) => {
const indexdata = fs.readFileSync("frontend/templates/pd2.html");
res.send(indexdata.toString());
});
app.post("/upload", (req, res) => {
const form = new Formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
if (err) {
res.status(404).send(`<h1>Sorry!! Requested page not found</h1>`);
}
cloudinary.uploader.upload(files.upload.filepath, function(error, result) {
console.log(result);
if (result != undefined) {
const urlpass = result.url;
//api fetch
let formData = new FormData();
formData.append('style', 'https://drive.google.com/uc?export=download&id=12X5T6_A9PfwJ0EBbEF5-wVbI5N3igaJ1');
formData.append('img', urlpass);
formData.append('type', '1');
const res1= fetch("http://@$@$@#/api",
{
body: formData,
method: "post"
})
.then(data => {
console.log(data);
}).catch(e => {
console.log(e);
});
const modelres= fetch("http://!@$@#$#/result/",
{
body: formData,
method: "get"
})
.then(data => {
console.log(data);
return data.toString();
}).catch(e => {
console.log(e);
});
//render
res.render("pdresult", { imagelink: modelres});
}
if (error) {
res.status(404).send(`<h1>Sorry!! Some error occured</h1>`);
}
});
});
});
