How to get file name from content-disposition

Here is how I used it sometime back. I’m assuming you are providing the attachment as a server response. I set the response header like this from my REST service response.setHeader(“Content-Disposition”, “attachment;filename=XYZ.csv”); function(response, status, xhr){ var filename = “”; var disposition = xhr.getResponseHeader(‘Content-Disposition’); if (disposition && disposition.indexOf(‘attachment’) !== -1) { var filenameRegex = /filename[^;=\n]*=(([‘”]).*?\2|[^;\n]*)/; var … Read more

How to have jQuery restrict file types on upload?

You can get the value of a file field just the same as any other field. You can’t alter it, however. So to superficially check if a file has the right extension, you could do something like this: var ext = $(‘#my_file_field’).val().split(‘.’).pop().toLowerCase(); if($.inArray(ext, [‘gif’,’png’,’jpg’,’jpeg’]) == -1) { alert(‘invalid extension!’); }

Which Visual C++ file types should be committed to version control?

Yes: cpp: source code filters: project file h: source code ico: resource rc: resource script rc2: resource script sln: project file txt: project element vcxproj: project file No: aps: last resource editor state exe: build result idb: build state ipch: build helper lastbuildstate: build helper lib: build result. Can be 3rd party log: build log … Read more

Node.js get file extension

I believe you can do the following to get the extension of a file name. var path = require(‘path’) path.extname(‘index.html’) // returns ‘.html’ If you would like to get all extensions in a file name (e.g. filename.css.gz => css.gz), try this: const ext=”filename.css.gz” .split(‘.’) .filter(Boolean) // removes empty extensions (e.g. `filename…txt`) .slice(1) .join(‘.’) console.log(ext) // … Read more

ReactJS – .JS vs .JSX

There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of resolving what type of file contents there is. There are however some other considerations when deciding what to put into a .js or a .jsx file type. Since JSX isn’t standard JavaScript one could argue that anything that is not “plain” … Read more