DropZone: How to Accept .csv Files? - dropzone

I've read quite a few answers on SO about this, and most advise using the acceptedFiles property to specify the accepted mime types.
However, the DropZone docs say:
Mime type determination is not reliable across platforms. CSV files,
for example, are reported as text/plain under macOS but as
application/vnd.ms-excel under Windows. In some cases there might not
be a mime type set at all.
I'm trying to upload a .csv file, and (using material-ui-dropzone), so far I've tried:
<Dropzone
acceptedFiles={['.csv', 'text/*']}
showPreviews={true}
showFileNamesInPreview={true}
/>
<Dropzone
acceptedFiles={'.csv', 'text/*'}
showPreviews={true}
showFileNamesInPreview={true}
/>
<Dropzone
acceptedFiles={'.csv', 'text/csv'}
showPreviews={true}
showFileNamesInPreview={true}
/>
...etc., but so far none are working:
The open file dialog shows .csv files as grayed out
Dragging-and-dropping a .csv file to DropZone gets a "File SeriesNotes.csv was rejected. File type not supported." message
What is the correct way to solve this for material-ui-dropzone (or for any version of DropZone)?

After lots of trial and error, this worked for me.
acceptedFiles={[".csv, text/csv, application/vnd.ms-excel, application/csv, text/x-csv, application/x-csv, text/comma-separated-values, text/x-comma-separated-values"]}
The main one on windows was the .csv the rest are just in case.

Related

Upload audio file to Jodit

I'm trying to configure my Jodit editor (v.3.0) in order to be able to upload also audio files.
I've put
$config['extensions'} = ['jpg', 'png', 'gif', 'jpeg', 'wav', 'mp3'];
in my config file and it stopped giving me the error "File type is not in white list", but it doesn't appear to execute any action.
What can I try?
Thanks
First you've closed the extensions array key with a } but I think is just a mistype
For the issue: I've figure out that the mp3 I'm trying to load is actually an mpeg file, even if the extension is .mp3
How to test: got to your connector, open the file connector>vendor>jodit>application>src>components>BaseApplication.php and comment out all the "if" statement with 'File type is not in white list' (for me is near line 365).
Now try to upload the file and you'll see the real extension. Mine was mpeg and after removing the comments to the BaseApplication.php file and adding the mpeg extention to the config.php the file was uploaded as expected.
Hope this can help you and a others (even my future me searching this issue again hehehe)

How to avoid Excel "bad format error" when saving spreadsheet

Using PHPSpreadsheet saving XLSX format works OK running the default code
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save("filename.xlsx");
But if I want to have the user to select the target directory using
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="filename.xlsx"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
$writer->save('php://output');
The file saves OK but Excel 2016 does not want to open it. Excel returns the following error
Excel Error
I looked through all documentation and posts but cannot find the solution.
Thanks !
Edit: Just in case, this solution does not work for me.
Edit 2: The sample provided Simple Download Xlsx works perfectly, but when doing a copy/paste for my spreadsheet, Chrome gives me a
Resource interpreted as Document but transferred with MIME type application/octet-stream
Edit 3: Used
ob_end_flush(); to clean any left over header in my code.
The file now saves OK, but needs repair when opening in Excel. Why ?
Thanks
Solution:
Bug from PhpSpreadsheet.
When using
header("Content-Type: application/vnd.ms-excel");
i.e. compatibility mode for Excel, the file opens OK.

Handling Binary (excel) file in Multi-data Post data in Suave.IO

I am trying to build a simple Suave.IO application to centralize the sending of emails. Currently the application has one endpoint that takes subject, body, recipients, attachments, and sender as form data and turns them into an EWS email message from a logging email account.
Everything works as intended in most cases, but I get a file corruption issue when one of the attachments is an excel file. In those cases, the file seems to get corrupted.
Currently, I am filtering the request.multipartFields down to only the ones that are marked as attachment files, and then doing this:
for (fileField: (string*string)) in fileFields do
let fname = (fst fileField)
let fpath = "uploadedFiles\\" + fname
File.WriteAllBytes(fpath, Encoding.ASCII.GetBytes (snd fileField)) |> ignore
The file path and the attachment names are then fed into the EWS message before sending.
Again, this seems to work with all attachments except attachments with binary. It seems like Suave.IO automatically encodes all multiPartFields as (string*string), which may require special handling when it's binary data.
How should I handle upload of binary files?
Thanks all in advance.
It looks like the issue was one of encoding. I was testing using python's request interface, and by default the files are encoded as multipart/form-data. By specifying a specific encoding for each file, I was able to help the server identify the incoming data as a file.
instead of
requests.post(url, data=data, files={filename: open(filepath, 'rb')})
I needed to make it
requests.post(url, data=data, files={filename: (filename, open(filepath, 'rb'), mimetypes.guess(filepath)})
With the second python script, files do end up in the files section of the request and I was able to save the excel file without corruption.

Grails - Jasper Plugin - Invalid byte 1 of 1-byte UTF-8 sequence error with .jasper file

I am using Grails 1.3.5, SQL Server 2005, iReports 3.7.6, Jasper Plugin 1.1.3. In my GSP page I have given the jasperReprt tag as:
<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />
</g:jasperReport>
For development, in Config.groovy I have specified the
jasper.dir.reports = './reports'
There are two files created in the reports folder when a new report is created and saved, i.e. report.jrxml and report.jasper.
When clicked on the PDF icon in IE or Firefox, an 500 server error is thrown and below is stack trace.
[2010-11-27 01:13:14.998] ERROR groovy.grails.web.errors.GrailsExceptionResolver Invalid byte 1 of 1-byte UTF-8 sequence.
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at
But if I delete the report1.jasper, the error is no longer thrown when PDF icon is clicked and the PDF report is shown fine.
Is this the correct way to do it?
My second issue is with using Sub Reports. Sub report is in the same folder as the main report. But When the report is executed from the application, below error is thrown:
[2010-11-27 01:30:27.556] ERROR groovy.grails.web.errors.GrailsExceptionResolver Could not load object from location : ./reports\report1sub_report.jasper
net.sf.jasperreports.engine.JRException: Could not load object from location : ./reports\urine_routinepatient_details_sub_report.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)
It does not find the sub report. How can I fix it?
Thank you.
Jay Chandran.
Edit:
I have been searching during this whole time, but still could not find a proper solution. So I did some trial and error. I figured out that, deleting report1.jasper and just leaving jasper.jrxml in the report directory works just fine as I said earlier.
For the sub-report issue: It was giving error Could not load object from location : ./reports\report1sub_report.jasper For some strange reason, the main report name report was getting appended to the name sub_report.jasper and was looking for a file named report1sub_report.jasper
So I created a sub-folder under reports folder and named it report1 and updated report1.jrxml file
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>
I had to add the extra \\ slash even though the "SUBREPORT_DIR" parameter had \\ the slashes at the end of the path as shown below.
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>
Notice the \\ at the end. I don't know why it was not getting appended!
Another way would have been to just change the sub-report name from sub_report.jasper
to report1sub_report.jasper!!! :)
I have tested this in production mode and it works fine. I am not sure if this is the way to do it, but all other possible solutions did not work for me.
Feedback will be very helpful.
I assume you have a version conflict here. iReport stores JRXML files and seems to compile them automatically to .jasper. The Grails Jasper plugin picks up the compile variant and gets into trouble with it. So try to disable compiled output in ireport.
The Grails Jasper plugin 1.1.3 uses internally Jasper 3.7.4, the used ireport is 3.7.6.
Regarding the sub reports: no idea.
The MalformedByteSequenceException is caused by a character encoding conflict. I'd suggest to use UTF-8 instead of Windows' Win-1252 (similar to ISO-8859-1) everywhere.
In Jasper's etc/ireport.conf file, change the default_options to:
default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"
(Where Xms and Xmx are unrelated memory settings. If there are default settings with that config entry, you can overtake them, else, just leave them out.)
See this forum thread for alternative configurations.
As for the error with subreports, take a look at the backslash \ that's probably wrong.
EDIT : There is some information about two issues which maybe could help in
http://grails.org/plugin/jasper#faqTab
i hope i can help with one of the issues: which one related with subreports dir.
The problem is the plugin code sets SUBREPORT_DIR to the complete file path of main report, including its name. However the code honour the user provided param with the same name, so if you fill this param with whatever value except null the plugin will use it.
For example if you chain directly the jasper controller you can do:
def renderAs(data,format) {
def reportParams=params.clone()
reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}
In your scenario an (ugly) option would be create an hidden input with name SUBREPORT_DIR and value the desired one. I would fill the paremeter in other way.
EDIT:
Another annoying problem is where do we have to put the main reports and compiled subreports:
When you run the app with run-app they work if you put them all in a folder with the same name as CH.config.jasper.dir.reports(reportDir) in the root of the grails app.
But if you want to deploy a war you have to put the main reports in a folder reportDir in the root of war file and compiled subreports in WEB-INF/classes/reportDir.
I've opted to keep all files in grailsApp/reports and copy the resources in the appropiate folders in the war grails task. In my BuildConfig.groovy i've added (reportDir is "reports"):
grails.war.resources = { stagingDir,args ->
def classpathDir="${stagingDir}/WEB-INF/classes"
copy(toDir:"${stagingDir}/reports") {
fileset(dir:"reports",includes:"**")
}
copy(toDir:"${classpathDir}/reports") {
fileset(dir:"reports",excludes:"**.jrxml")
}
}
Hope it helps.

PartCover browser not opening code files

We're generating PartCover reports via the command line tool along with our CruiseControl.Net unit tests. This generates an xml file that displays the results nicely on the cruisecontrol dashboard. The xslt transforms that are included only show you the percentage of coverage in an individual class. We want to know exactly what lines are not being covered. The problem ist when we open the report in the PartCover browser and double click a method it doesn't show us our cs files. I know the PartCover browser is capable of showing you the files because of the following.
Here's a screenshot of PartCover browser with the lines of code showing: http://kjkpub.s3.amazonaws.com/blog/img/partcover-browse.png.
The information looks like it should be available to the browser because the report contains this:
<Method name="get_DeviceType" sig="Cathexis.IDBlue.DeviceType ()" bodysize="19" flags="0" iflags="0">
<pt visit="2" pos="0" len="1" fid="82" sl="35" sc="13" el="35" ec="14" />
<pt visit="2" pos="1" len="4" fid="82" sl="36" sc="17" el="36" ec="39" />
<pt visit="2" pos="5" len="2" fid="82" sl="37" sc="13" el="37" ec="14" />
</Method>
and this:
<File id="66" url="D:\sandbox\idblue\idblue\trunk\software\code\driver\dotnet\Common\AsyncEventQueue.cs" />
All I want to be able to do is view what lines of code are not being covered in my test cases without having to figure out what the xml above is trying to tell me.
Thanks to anyone in advance who replies.
I figured out why the cs files were not displaying. The paths were incorrect in the xml file because our test project was being built on a different machine than the one partcover was on. (partcover must generate the .cs file paths from pdb files maybe?) Once I search and replaced the file switching the base directory of our subversion location to the one on the other machine all was well.

Resources