Highlighted

Coldfusion File uploading

New Here ,
Mar 21, 2018

Copy link to clipboard

Copied

I get the following error when trying to upload a Word doc with my CF based api.  This is not a MIME type I recognize for Word docs, so an error gets thrown by my code.

 

File type(application/x-tika-ooxml) is not supported.

 

This happens only for all Microsoft Office files. I believe it has something to do with CF's fileGetMimeType() function. Below is my code for uploading. Any thoughts on why I'm getting the above mime type, and if there is a way around it? I'm running CF2016(adobe 2016.0.05+303689). I'm using the CFWheels framework, but this has occurred with bare CF too. It is running off CF's built in web server.

 

 

  public function uploadFile(

 

   required file,

   required string filename

  ) {

   var myMimeType = fileGetMimeType(file);

   var isValidMime = false;

   var myExt = "";

   var targetPath = ExpandPath( "./" ) & '/files/bin/' & filename;


   for (var ext in application.wheels.mimetypes) {

   if (application.wheels.mimetypes["#ext#"] EQ myMimeType) {

   myExt = lCase(ext);

   isValidMime = true;

   break;

   }

   }


   if (isValidMime AND myExt NEQ "") {

   targetPath = targetPath & '.' & myExt;

   try {

   var result = fileUpload(targetPath, "file", myMimeType, "overwrite");


   if (!result.fileWasSaved) {

   throw ("Server failed to save the target file. Please contact a site admin.");

   }

   else {

   writelog("File Uploaded @ " & targetPath);

   }

   } catch (any e) {

   handleException(e);

   throw(

  message=e.message,

  errorcode=500

   );

   }

   }

   else {

   throw(

  message="File type(#myMimeType#) is not supported.",

  errorcode=400

   );

   }

  }

 

Views

261

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Coldfusion File uploading

New Here ,
Mar 21, 2018

Copy link to clipboard

Copied

I get the following error when trying to upload a Word doc with my CF based api.  This is not a MIME type I recognize for Word docs, so an error gets thrown by my code.

 

File type(application/x-tika-ooxml) is not supported.

 

This happens only for all Microsoft Office files. I believe it has something to do with CF's fileGetMimeType() function. Below is my code for uploading. Any thoughts on why I'm getting the above mime type, and if there is a way around it? I'm running CF2016(adobe 2016.0.05+303689). I'm using the CFWheels framework, but this has occurred with bare CF too. It is running off CF's built in web server.

 

 

  public function uploadFile(

 

   required file,

   required string filename

  ) {

   var myMimeType = fileGetMimeType(file);

   var isValidMime = false;

   var myExt = "";

   var targetPath = ExpandPath( "./" ) & '/files/bin/' & filename;


   for (var ext in application.wheels.mimetypes) {

   if (application.wheels.mimetypes["#ext#"] EQ myMimeType) {

   myExt = lCase(ext);

   isValidMime = true;

   break;

   }

   }


   if (isValidMime AND myExt NEQ "") {

   targetPath = targetPath & '.' & myExt;

   try {

   var result = fileUpload(targetPath, "file", myMimeType, "overwrite");


   if (!result.fileWasSaved) {

   throw ("Server failed to save the target file. Please contact a site admin.");

   }

   else {

   writelog("File Uploaded @ " & targetPath);

   }

   } catch (any e) {

   handleException(e);

   throw(

  message=e.message,

  errorcode=500

   );

   }

   }

   else {

   throw(

  message="File type(#myMimeType#) is not supported.",

  errorcode=400

   );

   }

  }

 

Views

262

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 21, 2018 0
Adobe Community Professional ,
Mar 21, 2018

Copy link to clipboard

Copied

I'm not sure why you're getting different MIME types than the normal ones, but I suggest you simply add all of the ones shown here:

[Tika-user] Problem detecting Microsoft Office formats from InputStream - Grokbase

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 21, 2018 0