Generator-jhipster: Opening a PDF in Chrome

Created on 29 Sep 2018  路  3Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

I've added a small entity:

entity Document {
name String,
file Blob
}

I've imported the jdl file, started the app and I've uploaded a PDF file. First thing when I browse the entity I see in the column FILE the link "Open", the type of file and the size of file. Is it not possible to get the file's name? Is it this information lost during the saving on the front-end or back-end? I see in the Document.java class an additional attribute FILE_CONTENT_TYPE. Maybe it would be useful to extend the entity with blob field with an attribute holding the file name?

But serious problem I have when I click on "Open" to retrieve a PDF file in Chrome. The browser first opens a new tab but this tab is empty. Firefox opens the file correctly in a new tab, Microsoft gives a possibility to save the file but prompts that is ".txt" file.

Motivation for or Use Case

A possibility to handle (upload/download) various types of files is very important in my application which I try to build based on JHipster.

Reproduce the error

The last version of JHipster (5.3.4). I've added only this one entity.

Related issues
Suggest a Fix
JHipster Version(s)

5.3.4

JHipster configuration

{
"generator-jhipster": {
"promptValues": {
"packageName": "com.mycompany.myapp",
"nativeLanguage": "en"
},
"jhipsterVersion": "5.3.4",
"applicationType": "monolith",
"baseName": "test01",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"clientFramework": "angularX",
"useSass": false,
"clientPackageManager": "npm",
"testFrameworks": [],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en",
"pl"
]
}
}

Entity configuration(s) entityName.json files generated in the .jhipster directory

{
"name": "Document",
"fields": [
{
"fieldName": "name",
"fieldType": "String"
},
{
"fieldName": "file",
"fieldType": "byte[]",
"fieldTypeBlobContent": "any"
}
],
"relationships": [],
"changelogDate": "20180929135217",
"entityTableName": "document",
"dto": "no",
"pagination": "no",
"service": "no",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"clientRootFolder": "",
"applications": "*"
}

Browsers and Operating System

Windows, Linux.

Most helpful comment

This could be done by adding a new FileBlob JDL type but as @jdubois said you will need to store the original name of the file and the Media Type (MIME type).

Also storing files in the database is not a great idea, what could be done is plugging Spring Data to an object storage using Spring Content (I think we add a feature request about this some time ago). Then during development, an S3 server can be easily bootstrapped with Minio.

All 3 comments

  • Yes I think the file name is lost, there should be another field for that, like FILE_CONTENT_TYPE
  • This part was made to handle images only, so if that's not an image you just have an octet stream. Indeed, it could be improved to handle PDFs - but I'm unusure if that could be automatic or if we need a specific type: instead of having image/blob we we would have image/PDF/blob

That's quite some work to have all this, so I'm adding a "feature request" tag, but I'm not sure anybody will do this (as you are the first one asking) - @edvjacek would you be ready to contribute on this part? We would of course help you.

This could be done by adding a new FileBlob JDL type but as @jdubois said you will need to store the original name of the file and the Media Type (MIME type).

Also storing files in the database is not a great idea, what could be done is plugging Spring Data to an object storage using Spring Content (I think we add a feature request about this some time ago). Then during development, an S3 server can be easily bootstrapped with Minio.

I'm closing this as I don't think this will be done (we have higher priorities and @edvjacek didn't comment). Also, that's a lot of code to test and maintain, not sure this would be good for the project in the long run.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dronavallisaikrishna picture dronavallisaikrishna  路  3Comments

cbornet picture cbornet  路  4Comments

Steven-Garcia picture Steven-Garcia  路  3Comments

frantzynicolas picture frantzynicolas  路  3Comments

pascalgrimaud picture pascalgrimaud  路  4Comments