473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Chunking

Anyone know any component or samples on how to chunk a big file(approx 5MB
+)
on the sending and receiving side ? File could be an image orplain text. Is it as simple as just looping through the streamon the sending side, sending a byte array and appending to afile on the server side, or does it require a much morecomplicted algorithm?
--------------------------------
From: Jonathan

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>KqhQOzLKBUS4g3MRSZj3ew==</Id>
Jul 21 '05 #1
2 1506
no, you are right, unless compression is involved just chunk it
out.................

byte[] buffer = socket.GetSocketOption(SocketOptionLevel.Socket,
SocketOpionName.SendBuffer);
int bytes = 0;

using (FileStream fromStream = new FileStream("path", FileMode.Open,
FileAccess.Read, FileShare.Read, buffer.Length))
{
while(bytes = fromStream.Read(buffer, 0, buffer.Length) > 0)
{
socket.Write(buffer, 0, bytes);
}
}
"Jonathan Eggert via .NET 247" <an*******@dotnet247.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Anyone know any component or samples on how to chunk a big file (approx 5MB
+)
on the sending and receiving side ? File could be an image or plain text. Is
it as simple as just looping through the stream on the sending side, sending
a byte array and appending to a file on the server side, or does it require
a much more complicted algorithm?
--------------------------------
From: Jonathan

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>KqhQOzLKBUS4g3MRSZj3ew==</Id>
Jul 21 '05 #2
Jonathan Eggert via .NET 247 wrote:
Anyone know any component or samples on how to chunk a big file
(approx 5MB+)


' send picture in 32KB blocks
const BLOCKSIZE as Integer=32768
' adjust next line to as required
Dim filepath as String="D:\pictures\" & Request.QueryString("f")
Dim objFileStream as FileStream=new FileStream(filepath, FileMode.Open,
FileAccess.Read)
Dim fileSize as Integer=objFileStream.Length
Dim offset as Integer=0
Dim length as Integer=0
Dim Buffer(BLOCKSIZE) as Byte
' change the filename= part as appropriate or leave it out completely
Response.AddHeader("Content-Disposition", "attachment;filename=" &
Request.QueryString("f"))
Response.AddHeader("Content-Length", fileSize.ToString())
Response.ContentType = "application/force-download"
while (offset<fileSize)
length = fileSize-offset
if (length<BLOCKSIZE) then
redim Buffer(length)
end if

if (length > BLOCKSIZE) then
length = BLOCKSIZE
end if
objFileStream.Read(Buffer, 0, length)
Response.BinaryWrite(Buffer)
Response.Flush()
offset+=length
end while
objFileStream.Close()

(some lines may wrap)

Andrew
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Uri | last post by:
I have a file that looks like this: (but longer, no wordwrap) Name: Date: Time: Company: Employee Number: Jim 2.03.04 12:00 JimEnt 4 Steve 3.04.32 ...
7
by: Stuart McGraw | last post by:
I just spent a $*#@!*&^&% hour registering at ^$#@#%^ Sourceforce and trying to submit a Python bug report but it still won't let me. I give up. Maybe someone who cares will see this post, or...
13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
2
by: Andy Leszczynski | last post by:
Does BaseHTTPServer.BaseHTTPRequestHandler support HTTP protocol chunking? Thanks, Andy
1
by: Doug Helm | last post by:
Hey, Folks: I'm writing a CGI to handle very large file uploads. I would like to include a progress bar. I think I'm about done. I have code to handle the file upload, and I think I can add...
5
by: z. f. | last post by:
hi, i have a vb.net web application and i make a request using internet explorer to an aspx page. the aspx page size if over 170KB, and the page in internet explorer looks truncated and in the...
0
by: Navin Mishra | last post by:
Has anybody looked into HTTP chunking to get events from web service to clients ? Basically one HTTP request to GetEvent() and them basically an infinite number of HTTP responses can be sent to the...
5
by: adhag | last post by:
Hi I am faced with quite a challenge. I need to open a 70-100 meg file and be able to chunk it out using AJAX back to the client but that isn't my problem really. What I need to do is open the...
7
by: russell.lane | last post by:
I've been looking at both MTOM and simple HTTP POST or PUT for file uploads. Some relevant details: ... We want to support programmatic file uploads from Winform apps. ... The files are large...
7
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.