Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apex-nitro upload is not considering .js files #351

Open
JoseArostegui opened this issue Dec 15, 2020 · 8 comments
Open

Apex-nitro upload is not considering .js files #351

JoseArostegui opened this issue Dec 15, 2020 · 8 comments

Comments

@JoseArostegui
Copy link

Issue Description

apex-nitro upload is not considering .js files

APEX Nitro Version

v5.0.2

Operating System

Windows 10

Node Version

v14.15.1

Browser

Chrome Version 87.0.4280.66 (Official Build) (64-bit)

APEX Version

20.2

Web Server

ORDS 19.2.0.r1991647, Tomcat 8

@JoseArostegui
Copy link
Author

C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro>apex-nitro upload
APEX Nitro
Your project is using Basic mode, so there is nothing to build.
Change your project to Pro mode or execute apex-nitro launch.
...Now uploading!
Uploading to 500 - Application Static Files...

SQLcl: Version 20.2 Production en mar dic 15 16:57:46 2020

Copyright (c) 1982, 2020, Oracle. Todos los derechos reservados.

Conectado a:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

Uploaded: C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro\src\app-icon.css
Uploaded: C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro\src\app-icon.svg
Uploaded: C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro\src\hero-logo.png
Uploaded: C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro\src\HeroIMT.css
Uploaded: C:\srcHeroApexIMT\trunk\Hero-Applications\Applications\IMT\imt-apex-nitro\src\hero_logo_2018.png

SQL>
Desconectado de Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

Files were uploaded successfully.

@vincentmorneau
Copy link
Collaborator

Can you tell me your java version please?

~/ $ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

@JoseArostegui
Copy link
Author

Thanks a lot for your help Vincent!

C:\WINDOWS\system32>java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)

@marvinamorim
Copy link

Is this the same problem of this issue over the apex-publish-static-files project?

@JoseArostegui
Copy link
Author

JoseArostegui commented Dec 17, 2020

Hi all,

We're in a hurry in the project and I've implemented a terrible workaround (thanks to @marvinamorim analysis) and now it works:

apex-publish-static-files\lib\distUpload.js:

/* get the mime type from a file name before loading it in the database */
helpers.getMimeTypeFromFile = function (fileName) {
	try {
		var extension;
		var i = fileName.toString().lastIndexOf('.');
		if (i > 0) {
			extension = fileName.toString().substring(i);
		}
		var mimeType = java.nio.file.Files.probeContentType(java.nio.file.Files.createTempFile("dummy", extension));
		
		if (extension==='.js') {
		   mimeType = 'application/javascript';
		}
		
		return mimeType;
	} catch (e) {
		ctx.write(e);
	}
};

Regards,
Jose.

@wiktusser
Copy link

wiktusser commented Feb 18, 2021

We have the same issue. It actually fails to set proper mime type for all filetypes (in our case .js .css .png),
we did a dirty fix on the DB side

SET TRANSACTION READ WRITE;
  
update APEX_200200.WWV_FLOW_COMPANY_STATIC_FILES
set MIME_TYPE = 'application/javascript' WHERE file_name like '%.js';

 

update APEX_200200.WWV_FLOW_COMPANY_STATIC_FILES
set MIME_TYPE = 'text/css' WHERE file_name like '%.css';

 

update APEX_200200.WWV_FLOW_COMPANY_STATIC_FILES
set MIME_TYPE = 'image/png' WHERE file_name like '%.png';

 

COMMIT;

@dwarcake
Copy link

A few of my colleagues had the same problem so one of them did some digging and came up with the reason and a possible solution.
See vincentmorneau/apex-publish-static-files#21 (comment) for this

@rgerteis
Copy link

Hi all,

it appears the none of the mime-types are not honored when uploading.
CSS, JS, Fonts, Images. They all get uploaded as text/txt.

Above SQL statement is a workaround hack that we have to apply manually.

@JoseArostegui : I don't think it's a terrible workaround. :-)

I think an update in the helpers.getMimeTypeFromFile could easily fix the problem.
It just needs to honor all types that are out there.

/* get the mime type from a file name before loading it in the database */
helpers.getMimeTypeFromFile = function (fileName) {
	try {
		var extension = 'text/txt';

		var i = fileName.toString().lastIndexOf('.');
		if (i > 0) {
			extension = fileName.toString().substring(i);
		}

		var mimeType = java.nio.file.Files.probeContentType(java.nio.file.Files.createTempFile("dummy", extension));
		
		if (extension==='.js') {
		   mimeType = 'application/javascript';
		}

		if (extension==='.png') {
		   mimeType = 'image/png';
		}

		if (extension==='.css') {
		   mimeType = 'text/css';
		}
		
		return mimeType;
	} catch (e) {
		ctx.write(e);
	}
};

Any chance this can be fixed and distributed into a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants