ich ein Bild-Upload in node.js schreiben, habe ich eine Datei vom Client hochgeladen:node.js Wie kann ich Datei-Uploads zusammenstellen?
<form id="frmImgUpload"
enctype="multipart/form-data"
action="/uploads/"
method="POST">
<input id="btnFile"
style="float:right;"
type="file"/>
<input id="btnUpload"
style="float:right;"
type="button"
value="Upload"/>
</form>
Der Code den Upload auszuführen:
$("#btnUpload").click(function() {
$("#btnFile").attr("name", strCompanyKey);
$("#frmImgUpload").submit();
});
Auf dem Server I angezeigt haben die Daten (nur ein kleiner Ausschnitt):
[ '------WebKitFormBoundaryI206ASCJdnqVyOo0\r\nContent-Disposition: form-data; name="syberdyne"; filename="simonplatten.png"\r\nContent-Type: image/png\r\n\r\n�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000l\b\u0006\u0000\u0000\u0000Ԃ\b�\u0000\u0000\u0000\tpHYs\u0000\u0000\u000b\u0013\u0000\u0000\u000b\u0013\u0001\u0000��\u0018\u0000\u0000\nOiCCPPhotoshop ICC profile\u0000\u0000xڝSgTS�\u0016=���BK���KoR\u0015\b RB��\u0014�',
'*!\t\u0010J���\u0015Q�\u0011EE\u0004\u001bȠ�\u0003����\u0015Q,\f�\n�\u0007����������{�kּ������>������\u0007�\b\f�H3Q5�\f�B\u001e\u0011�������[email protected]�\n$p\u0000\u0010\b�d!s�#\u0001\u0000�<<+"�\u0007�\u0000\u0001x�\u000b\b\u0000�M��0\u001c��\u000f�B�\\\u0001��\u0001�t�8K\b�\u0014\[email protected]�B�\[email protected]\u0001���',
Was würde ich zu tun ist, diese Daten in die ursprüngliche Datei wieder zusammenzusetzen. Sind das irgendwelche APIs oder Tutorials, die mir helfen, dies zu erreichen?
ich den Inhalt geteilt habe von dem Client empfangen:
var strBody = "";
request.on("data", function(chunk) {
strBody += chunk;
});
request.on("end", function() {
console.dir(strBody.split("\r\n"));
});
Daraus ergibt sich:
[ '------WebKitFormBoundarynBkMCKI8RBvIReTF',
'Content-Disposition: form-data; name="syberdyne";filename="simonplatten.png"','Content-Type: image/png','','�PNG','\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000l\b\u0006\u0000\u0000\u0000Ԃ\b�\u0000\u0000\u0000\tpHYs\u0000\u0000\u000b\u0013\u0000\u0000\u000b\u0013\u0001\u0000��\u0018\u0000\u0000\nOiCCPPhotoshop ICC profile\u0000\u0000xڝSgTS�\u0016=���BK���KoR\u0015\b RB��\u0014�&*!\t\u0010J���\u0015Q�\u0011EE\u0004\u001bȠ�\u0003����\u0015Q,\f�\n�\u0007����������{�kּ������>������\u0007�\b\f�H3Q5�\f�B\u001e\u0011�������[email protected]�001\u0000O��y���7\u0000\u0000\u0000\u0000IEND�B`�',
'------WebKitFormBoundarynBkMCKI8RBvIReTF--',
'' ]
Dies ist nur ein Ausschnitt der Daten, es sieht aus wie die binäre Daten codiert ist, irgendwie, gibt es eine Routine, die ich anrufen kann, um es zu entschlüsseln?
Ich habe 'formidable' installiert, was kann ich es analysieren?
https://coligo.io/building-ajax-file-uploader-with-node/ – Ouroborus
@Ouroborus, I Habe formidable heruntergeladen, was analysiere ich, ich benutze nicht express. – SPlatten
Formidable hat [Dokumentation] (https://github.com/felixge/node-formidable/blob/master/Readme.md). Anscheinend übergeben Sie das Anforderungsobjekt und eine Rückruffunktion. Der Rückruf und einige Ereignisse sind verfügbar, damit Sie etwas mit den Formulardaten tun können. Die Ereignisse 'field' und' file' sind wahrscheinlich für Sie von Interesse. – Ouroborus