WebService supports file upload on multiple platforms

Source: Internet
Author: User

To use a website to upload files, go to ASP. NET, I can basically think of two categories, one is to get file information through HTTP POST requests, the other is to publish services through WebService or WCF technology.

In the past, when I was working on the 3G camera project, I used HTTP POST to get photos. The method was very simple, that is, An aspx file (actually it works with asp, And it was implemented with asp at first, when aspx is used, there are still some moths), but the client (CAMERA) needs to understand the POST request and transmit the image into data. There is nothing wrong with this method, that is, there is always a problem when it is integrated into the system. I want to create multiple clients anyway, so I almost changed it to the second type.

 

The requirement is to be able to transmit files on multiple platforms (PC, Android, and iOS.

I would like to use WCF. I used it before and it is easy to get started, but others think that WCF may not be easy to use or use. NET platform Interconnection (no in-depth research, but I have seen someone calling WCF using android on the Internet, so I will discuss it later). Therefore, WebService is used honestly.

Android also seems to have two ways to call webservice. We implement ksoap2 call. First, I need to compile WEBSERVICE.

What parameters are used for transferring files?

I have no deep understanding about serialization. Let's talk about my views:

First of all, serialization seems to make objects available for storage and transmission. With this, you can easily implement some network applications. Then, KSOAP2 can serialize all basic data types. I can see that the string type is supported, but I do not know whether the byte [] type is supported or not.

Let's get back to the topic. Let's just get two of them. It's not that bad.

 

I have some doubts, So I first implemented the second method, through some method --- base64 encoding and decoding. Through this encoding, bytes can be converted into strings that can be directly transmitted over the network. After the server receives the data, it can obtain the original BYTE [] After decoding. The following lists the web functions.

[WebMethod(MessageName =   UploadSmallString( fileName, [] receivedBytes = (FileStream fs =   

The client can be encoded in base64 format. You can find a lot on the Internet. Careful guest may see the function name SmallString, right. This is suitable for transferring and transmitting large files when the file is not big?

Multipart! The advantage of multipart transmission is that it can support resumable data transfer. Let's talk about the implementation of the client:

1. Determine the file size 2. apply to multipart transmission 3. Call the service for operations

Then on the server side, write a reload, but the test fails. For more information, see configure (ConformsTo = WsiProfiles. basicProfile1_1)] if it is changed to None to support overloading, you may be afraid of compatibility issues.

                                                      [WebMethod(MessageName = , Description =   UploadBlobString( fileName,  serializedData,  blockSerial = [] receivedBytes = (blockSerial ==  (FileStream fs =  (FileStream fs =  -

After thinking about it, it seems that this can completely replace the previous method. It uses the default. NET parameter feature and specifies that blockSerial is 0 by default. If the client is interrupted, it will be okay from the start of the breakpoint blockSerial during the resume.

 

Next, let's talk about the first method, using bye.

[WebMethod(MessageName = , Description =   UploadSmallByte( fileName,  (FileStream fs =   

I have not tested this method, but one interesting thing is that if the string after ANDROID encoding BASE64 is directly passed to the byte [] parameter, this function can still work normally, the uploaded image can still be displayed normally. It is very strange. net. It cannot be compiled because of different types. You will have the opportunity to think about it later.

 

P.S. the BASE64 code can be passed through the ANDROID and PC platforms after testing. iOS is waiting for BASE64 implementation (it seems that there is no internal BASE64 encoding method). In principle, it should be fine, welcome to the discussion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.