Closed vimalraj-a closed 8 years ago
You guys are not taking this as serious issue?. I can't remove the file which is been downloaded before......
@cgarciae @austincummings @luizmineo Anyone have any idea?
@vimalraj-a What do you mean by "you can't remove it". Your Dart app can't remove it or the OS can't remove it? What happens if you run rm -rf path-to-filename
? What does the OS say?
I am using windows machine. I got error message from windows like 'file has been used by some other process'
Even after rebooting your computer?
No, Dart.exe process using that file. I can delete the file only if I stop redstone server app or killing dart.exe process.
By checking at https://github.com/dart-lang/shelf_static/blob/master/lib/src/static_handler.dart#L110 you might want to try to return a response.ok(file.openRead())
I am not able to find app.response.ok() method on redstone: 0.5.21+1. If you would add the snippet in this method would be great to me.
I'm not sure anymore about what the api looks like in 0.5.21+1, but you may want to look for shelf responses.
shelf.Response helloWorld(String fileName) { File f = new File("C:\Users\xxx\Desktop\$fileName"); Map headers = {"Content-Disposition" : 'attachment; filename="${web.request.url.pathSegments.last}"}';
return new shelf.Response.ok(f.openRead(), headers: headers); }
This works for me. Thanks @Pacane
Hi,
I have created a simple dart file server for downloading a file from server. I can download the file. But, I cannot delete the file from server after its downloaded.
here is my code :
import 'package:redstone/server.dart' as app; import 'dart:io'; import 'dart:async';
@app.Interceptor("/files/.*") downloadFileInterceptor() { app.chain.next(() => app.response.change( headers: { "Content-Disposition": "attachment; filename=\"${app.request.url.pathSegments.last}\"" })); }
@app.Route("/files/:fileName") Future helloWorld(String fileName) {
File f = new File("C:\Users\xxxx\Desktop\$fileName");
Future ff = new Future(() => f);
return ff;
}
main() { app.setupConsoleLog(); app.start(); }
Lets say I am downloading s.7z file from my desktop. I hope File instance for s.7z is not closed after response sent to client.