开发者

Shrink Uploaded file size (Image)

开发者 https://www.devze.com 2023-02-26 04:00 出处:网络
I Searched alot in the web but nothing ....... My Problem is that I want to reduce the actual size of any uploaded file to a specific length.

I Searched alot in the web but nothing .......

My Problem is that I want to reduce the actual size of any uploaded file to a specific length.

adnd I don't want to enforce the User to a specific ContentLength

ex:-

   Uploaded file size is 1mb (or whatever it's size) --> reduce it to 500kb

   Any Help .... I will be grateful .

To be more Specific I want to upload only Imag开发者_Python百科es if this gonna help.


So as I understand you want to allow user to upload file of any size but process on server only shrink file. And don't waste time and traffic on uploading whole file. So I don't know ability to interferer in process of receiving request body on IIS, that is why I propose to do shrinking on client side.

For that purpose you can use Silverlight, Flash. (Sure you cannot do it only with javascript because it has no access to client's file system). Here is example of implementing simple file upload using silverlight: Link. You will need to modify a bit code to cut file before upload.

Another variant is try to use Plupload. It allows you to upload files using HTML5 Gears, Silverlight, Flash providing ability of chunked uploads. You can try to investigate this opensource project in order to adapt it to suit your needs.

(You can also try to zip files on client side before sending)

Good luck.


If I understand your question correctly, I don't think that it is possible (or at least that easy). When a user uploads a file to your web site, the file is actually POST data. If you use a tool like Fiddler http://www.fiddler2.com/fiddler2/, you can see it in there, Base64 Encoded, if I remember correctly. So, the user has already sent the full data.

I see you have tagged your question with asp.net, so, at this point asp.net is looking at the request, checks posting's length against the max size allowed (configured in web.config) and will reject the post if it is too long before you even are allowed to see it (I've tried).

Best I figure you can do (if this is what you really need to do) is set the maxRequestLength in your web config to a value large enough that will not get rejected, and then truncate the data yourself.

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="32768" />
    </system.web>
</configuration>


You can increase the max. upload size by adding the following part to your web.config:

<system.web>
   <httpRuntime  maxRequestLength="102400" executionTimeout="360"/>
</system.web>

102400 == 1GB


Convert your file into byte array and split it into multiple byte arrays of your preferred size. Later if you want, write those arrays into multiple different files.

0

精彩评论

暂无评论...
验证码 换一张
取 消