Get file extension in client side with Fine-Uploader - fine-uploader

I am using Basic Fine-Uploader.
Is there any way to get the file extension before uploading it in client side when I select the it?

Use the getName API method to retrieve the name for a file when you have its id.
Keep in mind a few caveats, though:
In iOS all images are named "image.jpg"
Files submitted via drag and drop and paste are going to be named "blob" -- no extension, just blob.
Blobs are named "misc_data" by default by Fine Uploader. ()This can be changed via the blobs.defaultName option, and/or via the setName API method)

Related

Excel cannot open the file because the file format or file extension is not valid - PHP Maatwebsite

In our backend project, we have some features that allows to export files to xlsx.
We have done some tests locally and everything is working fine.
However, I deployed the app in an Azure App Service and some of the exports (not all) are not working fine.
I deployed backend (PHP), frontend (React) and database (MySQL) in Azure. I copied the information of the local DB to the DB deployed in azure (just because we don't wanna waste time with the data).
In the backend project, we are using Laravel with Maatwebsite for the features related to the exports. I created a class that implements FromQuery, WithHeading and ShouldAutoSize and that has construct, query and headings functions. Next, in a Controller, I use this structure to get the file:
public function functionName(Request $request){
$fileName= 'name'.time().'.xlsx';
return (new ClassThatHasTheLogicOfExporting($request->all()))->download($fileName);
}
All my exports works like that, but I'm getting the following error in some of them:
"Excel cannot open the file because the file format or file extension is not valid"
When I try to open the file.
I've been reading about the issue and some people says that I should use ob_start() (at the beggining of the class) and ob_end_clean() (just before exporting the file) but when I do this, I get a 404 error in the web app.
A curious thing is that when I add a filter to the data for exporting (for instance, downloading only the data of people in a specific city) (I can do it in the frontend app), the file opens without errors.
With this strategy, I've achieved downloading all the data in separate groups, so I don't think that the issue is related to special characters in the data.
Does anybody have any suggestion?
I'm using maatwebsite/excel 3.1 and PHP 8 with Laravel 8
I believe the error statement correctly suggests the error is being caused due to an invalid extension. Don’t worry there are several workarounds to this, I am sharing them below:
Method 1 – Change the Default File Format to Save Excel Workbooks
In Excel 2007, click the ‘Microsoft Office’ button and then ‘Excel Options’. In Excel 2010 and higher versions, click File > Options.
Select the Export option.
Select the Change File Type option.
Change the file extension, and then click Save As.
Method 2 – Recover Unsaved Workbook
Go to File and select the Info option.
Under Manage Versions, select ‘Recover Unsaved Workbooks’ op
If MS Excel has unsaved files then, it will list them. You can open and save it.
Method 3 – Use the' Open and Repair' Feature of MS Excel
Open MS Excel application.
Go to File and select the Open option.
Select the corrupt file and choose the Open and Repair option.
You can also check this forum:
https://social.technet.microsoft.com/forums/office/en-US/63020ccc-51d7-46d9-b956-121c0e6efcc8/excel-file-error-the-file-format-and-extension-dont-match?forum=Office2016ITPro
Best Regards,
Steve
you can add the below
if (ob_get_length() == 0 ) {
ob_start();
$response = Excel::download(new KingdomsExport, 'kingdoms.xlsx',\Maatwebsite\Excel\Excel::XLSX);
return $response;
}

Can I serve files stored in Google Cloud Storage via a http.FileServer in golang?

I have developed a small web application that runs a web server in golang.
Each user can login, view the list of their docs (previously uploaded) and click on an item to view an html page that shows some fields of the document plus an tag with a src attribute
The src attribute includes an url like "mydocuments/download/123-456-789.pdf"
On the server side I handle the URL ("mydocuments/download/*") via an http Handler
mymux.HandleFunc(pat.Get("/mydocuments/download/:docname"), DocDownloadHandler)
where:
I check that the user has the rights to view the document in the url
Then I create a fileserver that obviously re-maps the url to the real path of the folder where the files are stored on the filesystem of the server
fileServer := http.StripPrefix("/mydocs/download/",http.FileServer(http.Dir("/the-real-path-to-documents-folder/user-specific-folder/)))
and of course I serve the files
fileServer.ServeHTTP(w, r)
IMPORTANT: the directory where the documents are stored is not the static-files directory I sue for the website but a directory where all files end after being uploaded by users.
My QUESTION
As I am trying to convert the code for it to work also on Google Cloud, I am trying to change the code so that files are stored in a bucket (or, better in "sub-directories" -as they do not properly exist- of a bucket).
How can I modify the code so to map the real document url as available via the cloud storage bucket?
Can I still use the http.FileServer technique above (if so what should I use instead of http.Dir to map the bucket "sub-folder" path where the documents are stored)?
I hope I was enough clear to explain my issue...
I apologise in advance for any unclear point...
Some options are:
Give the user direct access to the resource using a signed URL.
Write code to proxy the request to GCS.
Use http.FS with an fs.FS backed by GCS.
It's possible that a fs.FS for GCS already exists, but you may need to write one.
You can use http.FileSystem since it is an interface and can be implemented however you like.

Password protected office files fail to upload using Attachment API

I am using ServiceNow Attachment API - POST /now/attachment/upload. This is working fine for all file types configured in Security properties. However it does not work when an attempt is made to upload a password protected office file, say Excel for example. I have tried uploading such file/s through their REST API Explorer as well as list item form with no luck.
When upload through SN form, the error received is "File mime type does not match the file content". SN form by always posts data as "application/octet-stream" however my upload script does set proper content-types and still fails. If content-type was the problem, it shouldn't have worked for unprotected file/s too.
Update
When I try to upload using REST API Explorer, it gives error for incorrect content-type. Same file without password works well. See screen shots below:
api/now/attachment/file
api/now/attachment/upload
You can upload password protected excel files to ServiceNow. Here is a snap shot where I uploaded a password protected attachment from REST API Explorer to an incident record. The content type really does not matter.
Setting MIME Type validation to false did the trick. This was acceptable in our case because we wanted to run PowerShell script that moved (uploaded) attachments from existing system to SN as part of data migration activity. It should ideally be turn on (true).

Receive file via websocket and save/write to local folder

Our application is entirely built on websockets. We don't do any HTTP request-reply. However, we are stuck with file download. If i receive file content via websockets can I wrote to local folder on user computer ?
If it makes a difference, we are only supporting Chrome so not issue if it doesn't work on other browsers.
Also, I know i can do this via HTTP. Trying to avoid it and stick to websockets since thats how the entire app is.
Thanks a lot in advance!
The solution depends on size of your file.
If size is less than about 50 MB, I would encode file's content to base64 string on the server and send this string to the client. Client should receive parts of the string, concat them to single result, and store. After receiving whole string, add link (tag <a>) to your page with attribute href set to "data:<data_type>;base64,<base64_encoded_file_content>". <data_type> is a mime type of your file, for example "text/html" or "image/png". Suggest file name by adding download attribute set to name of file (doesn't work for Chrome on OS X).
Unfortunately I have no solution for large files. Currently there is only FileEntry API that allows to write files with JS, but according to documentation it is supported only by Chrome v13+, learn more here https://developer.mozilla.org/en-US/docs/Web/API/FileEntry.

ASP.NET Membership Password Recovery E-mail [duplicate]

I am working on a simple portal application using the ASP.NET membership and login controls. I would like to use the PasswordRecovery control to send emails containing forgotten passwords, however my portal requires localization. I have an existing Content Management System that I am pulling the localized strings out of and I would like to link the PasswordRecovery control to that system.
But, it appears that the PasswordRecovery control will ONLY accept a .txt file for the email body...the property is PasswordRecovery1.MailDefinition.BodyFileName
I do not want to use a file on disk, I would like to use the localized content in my CMS.
Is there any way to do this? It occurred to me that I might be able to use the SendingMail event to send my OWN email through the normal System.Net namespace, but that seems sorta cludgy...
Any thoughts?
Thanks,
Max
Try handling the SendingMail event of the PasswordRecovery control. In that event, set the e.Message.Body and e.Message.Subject properties to your localized text.
Found this by googling "BodyFileName localization":
http://forums.asp.net/t/1118242.aspx:
Just bind the property to a key in
your page's localresource file. The
page's local resource file is the file
located in a subdirectory called
app_localresources in your page's
directory. Just use visual studio's
"tools -> create local resource"
option in design view for it be
created for you.
In that file, create a string
key/value pair with something like
Name: myBodyFileName
Value: myDefaultBodyFile.txt
Then bind this to the BodyFileName
property of the login control with
something like
'>
Then just create the sattelite local
resource files for other cultures and
map that key/value pair in those
resources to other body text files.
By the way, if you used visual studio
to create the resource file for you,
then the binding may have been done
for you automatticaly. Just search for
a
"MyChangePasswordControlResource1.BodyFileName"
key in the resource file or something
similar.
Regards, Jorge

Resources