HTML interface: file upload feature via HTML form and drag&drop#120
Conversation
62512b7 to
e6e0908
Compare
| BOOST_CHECK( files.contains( newValidFile )); | ||
| BOOST_CHECK( files.contains( "test.dcx" )); | ||
| BOOST_CHECK( files.contains( "test.dcxpreview" )); | ||
|
|
There was a problem hiding this comment.
Good, add one more check:
contentWindow->getContent()->getUri() == TEST_DIR + "/" + "uploaded.png";
| */ | ||
| const QString& getContentDir() const; | ||
|
|
||
| /** |
There was a problem hiding this comment.
line too long. Try to keep the brief < 80 char:
Get the directory for uploading content via web interface
| /** | ||
| * Get the directory for content uploaded via web interface and saved in a session. | ||
| * @return directory path | ||
| */ |
| function handleUploadFromMenu(evt) { | ||
| evt.stopPropagation(); | ||
| evt.preventDefault(); | ||
| // var files = evt.target.files ; |
|
|
||
| var totalSize = 0; | ||
| for (var i = 0, f; f = files[i]; i++) { | ||
| totalSize += (f.size / 1048576); |
There was a problem hiding this comment.
use a named constant for this magic number
| _server.handlePUT( "tide/upload/" + path, | ||
| [ this, fileName, path ] ( const std::string& data ) | ||
| { | ||
| const QString uploadDir = QDir::tempPath() + "/"; |
There was a problem hiding this comment.
not really needed, directly:
QFile file( QDir::tempPath() + "/" + fileName );
| QByteArray ba = QByteArray::fromRawData( data.c_str(), data.size( )); | ||
| QFile file( uploadDir + fileName ); | ||
| file.open( QIODevice::WriteOnly ); | ||
| file.write( ba ); |
There was a problem hiding this comment.
Both file.open() and file.write() could fail. This must be handled appropriately (at least return false)
| #ifndef FILERECEIVER_H | ||
| #define FILERECEIVER_H | ||
|
|
||
| //#include "types.h" |
| _impl->fileReceiver.reset( new FileReceiver( _impl->httpServer.get( ))); | ||
|
|
||
| connect( _impl->fileReceiver.get(), &FileReceiver::open, | ||
| [this]( QString uri ) |
There was a problem hiding this comment.
This function is duplicated from lines 124 - 127 !! It should have been a class function instead of two lambdas IF there was a need to check for relative paths, but that's not the case since FileReceiver always emits open with an absolute path, so here it is enough to just forward the signal...
| if( uri.startsWith( QDir::tempPath( ))) | ||
| { | ||
| const auto newUri = uploadDir + "/" + QFileInfo( uri ).fileName(); | ||
| QDir().rename( uri, newUri ); |
There was a problem hiding this comment.
The files should be placed in a subfolder with the session name, otherwise a second file with the same name will overwrite the one from a previous session:
uploads/sessionABC/image.png
uploads/sessionXYZ/image.png
Also, log a message if the rename operation fails for some reason and don't replace the window's content...
1d2f844 to
9edae5a
Compare
cddcaf6 to
e5fde41
Compare
e5fde41 to
c8aaa3c
Compare
No description provided.