0

I am trying to add filepond framework for me image input but whenever I try to submit my data it gets

Error: ER_DATA_TOO_LONG: Data too long for column.

I tried to add the issue in their GitHub because I believe that it is because of the framework or I am missing any dependencies for the framework but they replied:

Hi, this is a MySQL question and not a question related to FilePond library, please ask it on Stack Overflow.

enter image description here

.ejs file

<form class="add-music-form" action="/save" method="post">

<div class="form-group filepond-custom-style">
    <input  type="file" name="filepond">
</div>

<div class="form-group margin-top">
    <input type="text" class="form-control" placeholder="Title" id="title"  name="title">
</div>

<div class="form-group">
    <input type="text" class="form-control" placeholder="Band name" id="band_name" name="band_name">
</div>
<div class="form-group custom-file">
    <input type="file" class="custom-file-input" id="customFile" name="audio">
    <label class="custom-file-label" for="customFile">Select audio file</label>
</div>
<div class="mt-3">
    <button type="submit" class="btn btn-primary">Submit</button>
    <a data-dismiss="modal" class="btn btn-default">Cancel</a>
    </div>
</form>

app.js

app.post('/save',(req, res) => {
    let data = {filepond: req.body.filepond, title: req.body.title, band_name: req.body.band_name, audio: req.body.audio};
    let sql = "INSERT INTO music SET ?";
    let query = connection.query(sql,data,(err, results) => {
        if(err) throw err;
        res.redirect('/');
    });
});

enter image description here enter image description here enter image description here enter image description here

frustrated-dev
  • 431
  • 6
  • 29
  • 2
    What is the datatype for column `filepond`? – FanoFN Jul 29 '20 at 08:55
  • I set the image data type to vharchar because I want to store only the name of the file and the file itself will upload to my project directory /uploads/img.jp But I haven't set it the upload because of this error. – frustrated-dev Jul 29 '20 at 09:04
  • 1
    varchar but of how many characters? seems that you're trying to insert a string which is too long for that column! – Nir Alfasi Jul 29 '20 at 09:09
  • 1
    So you actually don't want to upload it into mysql table. How do you plan to separate between inserting the image filename data into mysql table and uploading the image itself to the directory? – FanoFN Jul 29 '20 at 09:10
  • @alfasin yah thats the problem why does my image file contains that huge amount of sting while the file name of it is just 4cd066c7c7f4430281d33cdd56aeafd9.jpg sql should store the file name of it and not those huge strings – frustrated-dev Jul 29 '20 at 09:17
  • @tcadidot0 yah you're right I have not yet doing the upload script nothing yet not part of that error. – frustrated-dev Jul 29 '20 at 09:23
  • 1
    `req.body.filepond` returns include a base-64 string value of the image. Maybe the question is "how to get filename value from filepond"? [does this help?](https://pqina.nl/filepond/docs/patterns/api/file/) – FanoFN Jul 29 '20 at 09:30
  • @tcadidot0Exactly! I didnt think that option. but how? – frustrated-dev Jul 29 '20 at 09:43
  • @tcadidot0 Hi I have new posts about multer you can join if you want https://stackoverflow.com/questions/63159597/multererror-unexpected-field-even-if-the-name-is-the-same – frustrated-dev Jul 29 '20 at 18:18
  • have you look into the link that I posted @exe? Does it help? Regarding on your follow up question about multer, I'm sorry but my node.js knowledge is quite elementary XD – FanoFN Jul 30 '20 at 00:13
  • 1
    @tcadidot0 yah I looked for it and tried some possible ways and nothing helped i still cant get the name of my file. I give up on this one and return to my regular image input that i customized css. – frustrated-dev Jul 30 '20 at 03:13

0 Answers0