panta / mongoose-file

Mongoose plugin adding a file field to a schema - useful for nodejs file uploads
MIT License
33 stars 2 forks source link

Upload Images/file #2

Open Zacknero opened 9 years ago

Zacknero commented 9 years ago

Ciao una volta salvato il file o immagine qual'è il codice per caricare l'immagine?? Sono alle prime armi con Mongoose+Express+MongoDB e sto cercando di capire meglio come implementare il tuo codice. Se puoi darmi una mano ne sono felice.

EDIT: ho tentato di configurare il file JavaScript ma mi da problemi con la variabile path

English version: Hello, when you save the file or image what is the code to load the image ?? I am a beginner with Express + Mongoose + MongoDB and I'm trying to better understand how to implement your code. If you can give me a hand I'm happy.

EDIT: I tried to configure the JavaScript file but gives me problems with the variable path

screenshot from 2014-09-08 15 20 05

panta commented 9 years ago

(English below the line. Please post questions in English, so also others can benefit from answers.)

Meglio non allegare immagini ma la trascrizione e/o di eventuali errori.

Il percorso dell'immagine è memorizzato nel campo path, quindi nel tuo caso sarebbe photoPippo.path. Il primo errore del tuo screenshot può essere risolto includendo il modulo path con:

var path = require("path");

Per il secondo bisognerebbe vedere cosa viene prima.

Comunque l'inizializzazione di uploads_base non è corretta: il primo parametro dev'essere una directory, non un file.

Per un esempio completo puoi vedere https://github.com/panta/mongoose-thumbnail-example


It's better to favour including transcriptions of code and/or errors instead of attaching images.

The path of the image is kept in the sub-field path, so in your case it would be photoPippo.path. The first error from your screenshot can be solved including the path module with:

var path = require("path");

For the other, it would be necessary to see the previous code.

By the way, the initialization of uploads_base is not correct: the first parameter should be a directory, not a file.

For a complete example, please see https://github.com/panta/mongoose-thumbnail-example

Zacknero commented 9 years ago

Grazie, ho risolto il problema del path con "require('path');" ed andando a controllare nel DB di Mongo risulta salvato. Una volta salvato devo seguire l'esempio nel link che hai postato?? O si ha un altra procedura?? Grazie ancora :)

English version: Thanks, I have solved the problem of path with "require ('path');" and going to check in Mongo DB is saved. Once saved I have to follow the example in the link you posted ?? Or do you have another procedure ?? Thanks again :)

panta commented 9 years ago

No need to write in Italian if you write in English :)

The example shows how to access the saved file contents from HTML (a Jade template actually). If you were building plain HTML from JS it would be something like this:

var HTML_IMG = "<img src='/uploads/'" + picture.photo.thumb.rel + "'>";

(in the example, the db record is picture and the picture field is photo).

Zacknero commented 9 years ago

You'll use the HTML code to take pictures but I was interested in how to load the contents of MongoDB, use Bootstrap and somehow I fix it. I'm interested in the final part, or how to load the image and display it on browswer.

In the example "mongoose-thumbnail-example" I performed the procedure but generates an error when loaded that you do not visulaizza the image.

If you want to open a thread on that topic and place the output of the error.

panta commented 9 years ago

The example also displays the images for all the uploaded records.

The snippet posted in my previous comment does exactly that: builds an <img> tag referencing an image from the DB.

I have just tried the example, and on my machine it works (did you install everything with "npm install" ?). Are you uploading images of known types (jpg, png)? What's the exact error?

Also, if you want and can, you can post here a link to a tarball or zip of your code (packaged as an npm module, with all dependencies/versions specified please).

Zacknero commented 9 years ago

It loads images like jpg or png. Now you place the image with the mistakes that brings me back after uploading an image (I speak of the example mongoose-thumbnail-example) with regard to post the "project" is a bit complex because I'm doing several tests I've seen created by the project MEAN.JS (http://meanjs.org/) and there is confusion between the various CRUD.

screenshot from 2014-09-08 16 25 20

panta commented 9 years ago

Which version of node are you using? Can you try with a 0.10.x (I've tested with 0.10.13 right now).

Zacknero commented 9 years ago

I use this version: v0.10.25

EDIT: So what's the problem ??