sendfile

Fetch image in React from Node.js request

帅比萌擦擦* 提交于 2021-02-19 08:56:14
问题 When needed, React asks for an image using Superagent : exports.getImgFromSection=function(id,request){ request .get('/img/'+id) .end((error, response) => { if (!error && response) { console.log(response.file); } else { console.log('There was an error fetching server', error); } }) } Node.js answers this way : app.get("/img/:id",function(req, res){ // check if exists and then res.sendFile(path.join(__dirname, './data/img/'+req.params['id']+'.png')); }); But I don't know how to get the image

NodeJS sendFile with File Name in download

落花浮王杯 提交于 2020-02-19 10:47:13
问题 I try to send file to client with this code: router.get('/get/myfile', function (req, res, next) { res.sendFile("/other_file_name.dat"); }); it's work fine but I need that when user download this file from the url: http://mynodejssite.com/get/myfile the filename into the browser must be "other_file_name.dat" and not "myfile". 回答1: there is a specialized method res.download which covers all for you ;) router.get('/get/myfile', function (req, res) { res.download("/file_in_filesystem.dat", "name

Understanding sendfile() and splice()

会有一股神秘感。 提交于 2019-12-30 02:19:47
问题 sendfile() can be used to transmit data from a "file" descriptor to a "socket" descriptor in order to get data from machine A to machine B. Is it possible to get the data at the receiving end from the "socket" descriptor to a file with similar zero-copy semantics? I think sendfile() doesn't help here because sendfile() needs the source of data to be "page/buffer" cache. Is my understanding correct? Can splice() help in this situation? 回答1: You're correct about the limitation of sendfile for

How to solve the memory-leak with send_file (or send_data) on Heroku?

房东的猫 提交于 2019-12-24 14:06:26
问题 I have a Rails 3 app that needs to generate an image and send the data to the browser. The app must be deployed on Heroku. However, Heroku only supports streaming through Mongrel which holds on to the memory. This then causes Heroku to slow, then kill the thread after a dozen or so requests. https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded I am currently using send_data or send_file from ActionController::DataStreaming http://api.rubyonrails.org/classes

Jboss AS7, APR native connectors and sendfile

橙三吉。 提交于 2019-12-23 01:14:06
问题 I've set out on an endeavour to implement support for a feature similar to mod_xsendfile on torquebox (www.torquebox.org). Torquebox is basically a bunch of code on top of JBoss AS 7, which makes my effort kinda equivalent to making sendfile work on JBoss AS 7. The main problem here is probably my confusion over JBoss, but after wasting way too many hours exhausting all my googling resources, I have to beleive that there's someone out there who actually know how this thing works in AS 7. As I

Minimizing copies when writing large data to a socket

青春壹個敷衍的年華 提交于 2019-12-20 12:36:13
问题 I am writing an application server that processes images (large data). I am trying to minimize copies when sending image data back to clients. The processed images I need to send to clients are in buffers obtained from jemalloc. The ways I have thought of sending the data back to the client is: 1) Simple write call. // Allocate buffer buf. // Store image data in this buffer. write(socket, buf, len); 2) I obtain the buffer through mmap instead of jemalloc, though I presume jemalloc already

How to download file with send_file?

那年仲夏 提交于 2019-12-20 02:11:36
问题 Can someone enlighten me how can I download file with send_file ? I have a file image.jpg inside app/assets/images . I've tried this in my controller: def download send_file ("#{Rails.root}/public/images/image.jpg") end def download send_file ("#{Rails.root}/assets/images/image.jpg") end def download send_file ("#{Rails.root}/images/image.jpg") end def download send_file ("/public/images/image.jpg") end def download send_file ("/assets/public/images/image.jpg") end def download send_file ("

c send and receive file

依然范特西╮ 提交于 2019-12-18 10:21:11
问题 This is the server (sendfile) part: offset = 0; for (size_to_send = fsize; size_to_send > 0; ){ rc = sendfile(newsockd, fd, &offset, size_to_send); if (rc <= 0){ perror("sendfile"); onexit(newsockd, sockd, fd, 3); } offset += rc; size_to_send -= rc; } close(fd); /* la chiusura del file va qui altrimenti rischio loop infinito e scrittura all'interno del file */ memset(buffer, 0, sizeof(buffer)); strcpy(buffer, "226 File Successfully transfered\n"); if(send(newsockd, buffer, strlen(buffer), 0)

Use sendfile() to copy file with threads or other efficient copy file method

五迷三道 提交于 2019-12-13 04:14:17
问题 I'm trying to use the Linux system call sendfile() to copy a file using threads. I'm interested in optimizing these parts of the code: fseek(fin, size * (number) / MAX_THREADS, SEEK_SET); fseek(fout, size * (number) / MAX_THREADS, SEEK_SET); /* ... */ fwrite(buff, 1, len, fout); Code: void* FileOperate::FileCpThread::threadCp(void *param) { Info *ft = (Info *)param; FILE *fin = fopen(ft->fromfile, "r+"); FILE *fout = fopen(ft->tofile, "w+"); int size = getFileSize(ft->fromfile); int number =

Django download file empty

心不动则不痛 提交于 2019-12-12 10:06:28
问题 I am writing a simple function for downloading a certain file, from the server, to my machine. The file is unique represented by its id. The file is locatd corectly, and the download is done, but the downloaded file (though named as the one on the server) is empty. my download function looks like this: def download_course(request, id): course = Courses.objects.get(pk = id).course path_to_file = 'root/cFolder' filename = __file__ # Select your file here. wrapper = FileWrapper(file(filename))