Downloading file from storage folder not working - lumen

I'm trying to download pdf file from public folder in my lumen 8 application. The exact file path is public/assets/attachments/resume.pdf. My code is
public function downloadResume()
{
return response()->download('public/assets/attachments/resume.pdf');
}
as per suggested here.
However the code is throwing following error:
What's the proper way to downloding the file ?

Related

Trying to return a static file in web.py but getting "not found" error message

I have a web.py server hosted on pythonanywhere.com doing some handy things with python.
Now I'd like to just serve a straightforward html file from the same server i.e. just return the contents of a static html file to the client
The comments/answers below state that it should be possible, out of the box, to serve static files in the static directory, located in the same directory as the main python file which contains the following :
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, Joe'
if __name__ == "__main__":
app.run()
The server above works fine, when I go to http://myhost/ it displays "Hello , Joe".
The directory static exists and contains a file small.jpg but when I try the url http://myhost/static/small.jpg it gives me "not found"
Previous text of question up to Nov 9th 2022 is below :
original question title : Trying to return a html file in web.py but getting "No template named ....." error message
So I've looked at the web.py documentation on serving static files and templating and I think the following code should work :
import web
render = web.template.render('static/')
# have also tried render = web.template.render('/full/path/to/static/')
urls = (
'/getlatlongEIRCODE', 'getlatlongEIRCODE', #other stuff
'/getlatlongGOOGLE', 'getlatlongGOOGLE', #other stuff
'/getmonthlyPV', 'getmonthlyPV', #other stuff
'/Tomas', 'Tomas',
)
class Tomas:
def GET(self):
return render.Tomas()
I have created a folder static at the same level as my file above (which works fine for the other scripts) and i have created a file Tomas.html in the static folder containing
<h1>Help me</h1>
However I get an error message when I go to https://example.com/Tomas
<class 'AttributeError'> at /Tomas
No template named Tomas
P.S. From the static files page it seems to say I should just be able to put the Tomas.html file in a folder called "static" and then access is via https://example.com/static/Tomas.html but that is not working (it returns "not found")
You're using a relative path to your template directory without paying attention to the working directory. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/
You're working too hard. 'static' is built in.
As the documentation says, http://localhost/static/logo.png will return the file logo.png from the existing directory static, which is relative to your webserver root.
Do not use render() for this (not needed). Also, do not list your desired file ('/Tomas') in the urls list (not needed).
Anything under the static directory can be accessed with the url https://localhost/static/...
"static" is hardcoded in the web.py server, so you cannot (easily) change this to some other folder. The suggestion in the web.py documents is to have nginx or apache host your application and use an Alias there to go to web.py static. (I think you can also add StaticMiddleware to your web.py application, but you'd need to investigate that yourself -- look at web.application.run()
The case of the disappearing /static/ directory was related to the fact that I'm hosting on pythonanywhere.com
Even though the web.py documentation says that the /static/ folder is plugged in by default, that's not the case in pythonanywhere and you need to expressly make the link between the url http://yourhost/static/ and /path/to/static in the Web part of the dashboard.

Cannot delete file using SharpSvn: {filepath} is not a working copy

I am unable to delete a file from SVN using SharpSvn.
Here is my code:
using (SvnClient client = new SvnClient())
{
// snip...
string filePath = "C:\\path\\to\\file.txt";
client.Delete(filePath, deleteArgs);
}
Here is the exception:
SharpSvn.SvnInvalidNodeKindException: ''C:\path\to\file.txt' is not a working copy'
I confirmed this filepath exists and is tied to SVN. What is the problem?
This question led me to the answer. I was using the incorrect casing in my filepath. Following the example above, maybe I tried to delete the file "C:\path\to\file.txt" but the actual path on disk was "C:\PATH\TO\file.txt". I fixed by using SvnTools.GetTruePath:
client.Delete(SvnTools.GetTruePath(filePath), deleteArgs);

security error on getFile call on given directory entry in chrome app

Summary : I am downloading files to chrome app sandbox file system. I have directory called 'downloads' in chrome app's sandbox file system.Following is the code sample
var getSubDirectory = function()
{
subdir.getFile('demo',{create: true},function(fentry)
{
console.log(fentry);
},errohandler)
}
subdir is directory entry. subdir is returning properly, I am getting its output.But when i try to create file into that directory using getFile function, it throws security error.I have permission in manifest for the filesystem.write and filesyste.directory.I tried isWritableEntry() on subdir, its returning false.

How to read a file from WEB-INF/resources folder?

I am using Icefaces for webapplication development. I wish to read a file from the resources folder and use it in the sessionbean.
Actually I wish to setup Jasper Reports. I have already setup the libraries in the classpath. The problem I get is while fetching the file from /WEB-INF/resources/ folder. Everytime I run the code from SessionBean, I get the exception:
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: /resources/reports/myreport.jrxml (No such file or directory)
The Code I use is:
public void generateReport() {
try {
JasperCompileManager.compileReportToFile(
"/resources/reports/myreport.jrxml",
"/resources/reports/myreport.jasper");
} catch (Exception e) {
e.printStackTrace();
}
}
The above code is in the SessionBean.
Plz help
You are passing relative
URLs to method JasperCompileManager.compileReportToFile.
This method expects filenames as parameters, not URLs.
The solution suggested in other internet forums is:
JasperCompileManager.compileReportToFile(
getServletContext().getRealPath(xmlFile),
getServletContext().getRealPath(compiledFile));

ASP.NET MVC: Can an MSI file be returned via a FileContentResult without breaking the install package?

I'm using this code to return a FileContentResult with an MSI file for the user to download in my ASP.NET MVC controller:
using (StreamReader reader = new StreamReader(#"c:\WixTest.msi"))
{
Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd());
return File(bytes, "text/plain", "download.msi");
}
I can download the file, but when I try to run the installer I get an error message saying:
This installation package could not be
opened. Contact the application vendor
to verify that this is a valid Windows
Installer package.
I know the problem isn't C:\WixTest.msi, because it runs just fine if I use the local copy. I don't think I'm using the wrong MIME type, because I can get something similar with just using File.Copy and returning the copied file via a FilePathResult (without using a StreamReader) that does run properly after download.
I need to use the FileContentResult, however, so that I can delete the copy of the file that I'm making (which I can do once I've loaded it into memory).
I'm thinking I'm invalidating the install package by copying or encoding the file. Is there a way to read an MSI file into memory, and to return it via a FileContentResult without corrupting the install package?
Solution:
using (FileStream stream = new FileStream(#"c:\WixTest.msi", FileMode.Open))
{
BinaryReader reader = new BinaryReader(stream);
Byte[] bytes = reader.ReadBytes(Convert.ToInt32(stream.Length));
return File(bytes, "application/msi", "download.msi");
}
Try using binary encoding and content-type application/msi instead of text/plain - it's not ASCII or text content so you're mangling the file.