Asp.net core file download corrupt - asp.net-core

I've been trying to provide an epub download in various ways. All of them work when downloading on my laptop with any browser, but when downloading with the e-reader it results in either a "file is corrupt" or "content type not supported". The problem is not with the file itself: When I upload it to any other place (e.g. public file dump websites) I can download the file without any issues to my e-reader.
Here's one of the many ways I've tried:
IFileProvider provider = new PhysicalFileProvider(path);
IFileInfo fileInfo = provider.GetFileInfo(filename);
var readStream = fileInfo.CreateReadStream();
var fileType = "application/epub+zip"; //MediaTypeNames.Application.Octet
return File(readStream, fileType, Path.GetFileName(outputFilepath));
and on the razor page e.g.:
Epub2
Epub2
(here the first link results in "corrupt file" and the second in "content type not supported).
On the server, the file is placed outside the website root.
What are some possible reasons that the direct download to my e-reader doesn't work with this code, yet with plain file uploads/downloads it works?
Thanks a lot for your help!

The issue was the download over https to my Tolino e-reader. This specific old Tolino model has issues with downloads over https, when I switched to http I could successfully download the ebook.

Related

Browser cannot download .txt file if the project is .Net Core Restful API

I am trying to activate my SSL for my project but one of the the urls doesn't respond.
This is the web site and when you paste the url to the browser, it downloads the .txt file.
http://www.xxx.co.uk/.well-known/pki-validation/83CB00D29E282E1FFD6DFB220F030EF4.txt
This is the Restful .Net Core API domain and when you paste the url to the browser, it returns 404 error.
http://api.xxx.co.uk/.well-known/pki-validation/83CB00D29E282E1FFD6DFB220F030EF4.txt
Under the IIS I have compared the psychical paths, permissions and it seems everything is same. I believe something in Rest API blocks the .txt file download. Should I check the web.config or something I need to add to the C# source code? Should I update ConfigureServices(IServiceCollection services)? In IIS I have checked MIME Types and the .txt is already defined.
Any suggestions?
I believe my problem is pointing to this subject but I am not sure how to enable/define .txt files in startup.cs. Any code snippets?
How to Serve Static File
EDIT: Finally I found a solution. Now the browser can download the .txt files. What I did is, I created a virtual directory in IIS. Here are the steps:
Go to the C: drive
Create a new folder called well-known
Inside the .well-known folder, create another folder named pki-validation
so far, your folders should look like this: C:\.well-known\pki-validation
Upload the TXT file in the pki-validation folder
Open the IIS Manager on your server
Do a right click on your website and select Add Virtual Directory
In the Alias section write .well-known
In the Psychical Path area enter the path to the well known folder. For example: C:\well-known
Press OK to create this alias
The urls are now serving the .txt files. I hope these steps one day saves the other developers time.

How can I set a file upload function?

I am creating an SAPUI5 WebApp with an file upload function. I try this example from SAPUi5 Explored: sap.m.sample.UploadCollection
I try with my trial account in SAP WebIDE to set the upload function ( Upload Collection)
The issue is, not allowing to upload a file in the project folder or local desktop folder.
If I upload a file it appears but i can't open it and I get a 405 HTTP
error.
Any Ideas, what the problem is?
like you see already in your posts comments, you need a backend for this task. The UploadCollection control is only usable with a backend in the background which receives the transmitted file from the control.
On the page https://sapui5.hana.ondemand.com/#/api/sap.m.UploadCollection you see
This control allows you to upload single or multiple files from your devices (desktop, tablet or phone) and attach them to the application
while you can replace "application" with "receiving backend"
Indipendent of this may I allowed to ask where do you think the file should be uploaded when not to a backend system? I mean when you choose a file from your local storage it doesn't make any sense to upload it again to your local storage?!

static site hosting on S3 - 404 errors on files that show in S3 management console

I'm hosting a site using S3. Until recently, no problems. Last week, I uploaded some new .html files, and all of these new files result in a 404 error, while older .html files load with no problems.
I can see the new files in the S3 bucket using the web interface. When I compare permissions and any other settings for the new vs. old files, I'm not able to see any difference. When I view the properties of a new file, the provided link works (none of my images or CSS loads, however). Also, I can get the file to load using the bucket's endpoint. But, when using our custom domain name, all new files fail to load, with the following error:
404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: test1/s3a-debug.html
RequestId: 2573FF0356xxxxxxxxxx
HostId: qYnv8alWnV/xxxxxxxxx/xxxxxxxxxxxx+NPkHLO8arfTVizUds=
I'm at a loss to explain why recently uploaded files throw a 404, and yet older files that look identical load just fine. I've seen other people report similar problems, but I've yet to find a thread with a solution.
any help would be greatly appreciated. Thanks!
Go to S3 bucket properties -> Static web hosting and add index.html as Error document.
It considers everything as directory once you append something to host URL. Now after adding index.html as Error document, when it doesn't find the required path as a folder, it will go to index.html and redirect your request.

Server side: detecting if a user is downloading (save as...) or visualizing a file in the browser

I'm writing an apache2 module
by default and when viewed in a web browser, the module would only print the first lines of a large file and convert them to HTML.
if the user choose to 'download as...', the whole raw file would be downloaded.
Is it possible to detect this choice on the server side ? (for example is there a specific http header set ?).
note: I would like to avoid any parameter in the GET url (e.g: "http://example.org/file?mode=raw" )
Pierre
added my own answer to close the question: as said #alexeyten there is no difference. I ended by a javascript code the alter the index.html file generated by apache.

Display list files and folder using Mediafire API

I tryed to use Mediafire API, but when I use Folder, get_info, it doesn't return file & folder array like the example.
Full url I used: http://www.mediafire.com/api/folder/get_info.php?folder_key=l461cm2d8hfxd
What's wrong with my attempt? Thank you.
You can try the MediaFire API PHP Library. This class currently implements all the functions in the Mediafire API.
Ok I just took a look at their API documentation. They've updated the get_info function for the folders. They've taken out the file tree....
So if you are uploading via the dropbox (which doesn't return the quickkey associated with the file), you CAN NEVER dropbox upload and then use the api to find the file and download it. This renders their API as useless as tits on a boar hog.
The point of a dropbox is to allow remote uploads to a folder, you then know the folder key so you can query the API and return the document quickkeys that are in the folder which then allows you to manage those files remotely, move, delete, download etc. Now you cannot do this FAIL FAIL FAIL.
Despite the Functionality of get_info not working, folder search can resolve at least some issues with retrieving quick keys. In my case i searched for ".mp3" and was handed all the mp3s in my folder