Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:24:27+00:00 2026-06-05T00:24:27+00:00

i implemented a code using ASIFormDataRequest to upload a file to server my code

  • 0

i implemented a code using ASIFormDataRequest to upload a file to server

my code goes like this:

   NSURL *url = [NSURL URLWithString:@"someurl"];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"medelix.db" ofType:nil];  
    NSData *myData = [NSData dataWithContentsOfFile:filePath]; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:@"file" forKey:@"serverIP"];


    [request setData:myData withFileName:@"Data.txt" andContentType:@"application/octet-stream" forKey:@"uploadedfile"];
   // [request setProgressDelegate:self];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(postFinished:)];
    [request setDidFailSelector:@selector(postFailed:)];

    [request startAsynchronous];

    NSData *newStringData = [request responseData];
    NSString *x = [[[NSString alloc] initWithData:newStringData encoding:NSUTF8StringEncoding] autorelease];
    NSLog(@"result text from server is %@", x);

my server side PHP is :

<?php

$target_path = '/Applications/XAMPP/xamppfiles/htdocs/myupload/';

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
{ 
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
} 
else{ 
    echo "There was an error uploading the file, please try again!";
}

?>

Bug I found while running :request responseData does not gave any thing

Now i wants to send a Block of data to server through ASIFormDataRequest,until the file contain is not finished (sending file contain chunk by chunk ).

can any body suggest me with a piece of code that how to send data chunk by chunk using ASIFormDataRequest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:24:29+00:00Added an answer on June 5, 2026 at 12:24 am

    Your Upload native code look som thing like this :

    - (void)uploadSomethingFiveTimes:(NSURL *)url
    {
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"medelix.db" ofType:nil];  
    
        NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath: filePath];
        ASINetworkQueue *myQueue=[[ASINetworkQueue alloc] init] ;
        [myQueue cancelAllOperations];
        [myQueue setUploadProgressDelegate:myProgressIndicator];
    
        [myQueue setDelegate:self];
        [myQueue setRequestDidFinishSelector:@selector(queueComplete:)];
        int index;
     NSData *myData=nil;
        int Filedata= [file seekToEndOfFile];
        Filedata=(Filedata/3);
       [file seekToFileOffset:0];
    
        NSLog (@"Offset = %llu", [file offsetInFile]);
    
        for (index=3; index>0; index--) {
    
    
             myData = [file readDataOfLength: Filedata];
    
            NSString *x1 = [[[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding] autorelease];
            NSLog(@"responseData=%@",x1);
    
    
             NSLog (@"Offset = %llu", [file offsetInFile]);
    
            ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
            [request setDelegate:self];
            [request setDidFinishSelector:@selector(postFinished:)];
            [request setDidFailSelector:@selector(postFailed:)];
            [request timeOutSeconds];
            [request setNumberOfTimesToRetryOnTimeout:2];
            [request setPersistentConnectionTimeoutSeconds:120];
            [request setShowAccurateProgress:YES];
             NSString *ServerFileName=[NSString stringWithFormat:@"%@_%@",[self getcurrentdateTime],@"medelix.db"];
    
              [request setData:myData withFileName:ServerFileName andContentType:@"application/x-www-form-urlencoded" forKey:@"uploadedfile"];
            NSString *x = [[[NSString alloc] initWithData:[request responseData]encoding:NSUTF8StringEncoding] autorelease];
            NSLog(@"responseData=%@",x);
          ⠀
            [myQueue addOperation:request];
        }
        [myQueue go];
    
    }
    
    
    
    
    - (void)postFinished:(ASIFormDataRequest *)request
    {
        // NSData *newStringData = [request responseData];
        NSString *x = [[[NSString alloc] initWithData:[request responseData]encoding:NSUTF8StringEncoding] autorelease];
    
        NSLog(@"Post Success %d [request responseData]=%@",[request inProgress],x);
        NSLog(@"Post Success %@" ,[request timeOutSeconds]);
    }
    - (void)postFailed:(ASIFormDataRequest *)request
    {
        NSLog(@"Post Failed %d",[request inProgress]);
         NSLog(@"Post Failed %@",[request error]);
    }
    
    
    
    
    - (void)queueComplete:(ASINetworkQueue *)queue
    {
        //[queue requestsCount];
      // NSLog(@"Max:%d", );
        NSLog(@"Max: %f, Value: %f", [myProgressIndicator progress],[myProgressIndicator progress]);
    }
    

    And the server side code will be :–

    +

    <?php
    
        $target_path = '/Applications/XAMPP/xamppfiles/htdocs/myupload/';
    
        $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    
        $myFile=$_FILES['uploadedfile']['name'];
        echo $myFile." 1st line \n";
    
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
        { 
            echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
        } 
        else{ 
            echo "There was an error uploading the file, please try again!";
        }
    
        if(file_exists($myFile))
    
        {
    
            $file="server_".$_FILES['uploadedfile']['name'];
    
    
             //exec("chmod $target_path 0777");
             if( chmod($_FILES['uploadedfile']['tmp_name'], 777))
             {
             echo "YES!";
             }
            if( chmod($target_path, 777))
            {
                echo "YES";
            }
            else
            {
                echo "NO";
            }
    
           $fh = fopen($target_path,'r');
           // $file='/Applications/XAMPP/xamppfiles/htdocs/myupload/server';
           $ab=file_put_contents($file, fread($fh,filesize($target_path)),FILE_APPEND);
            echo "Fread".$ab;
        //    fwrite($fh,"\n");
            fclose($fh);
            echo $fh." 2st line \n".$target_path." \n";
    
    
        }
    
        unlink($target_path);
    
    
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the image upload code using jquery php in my php web
Hello i had implemented this code Using your own SQLite database in Android applications
I have implemented Tabbar in sencha touch without any content as follows: using code
I have a few Collapsible segments in my Code which i have implemented using
I would like to implement a parallel version of the code below using threads
I have some parallel code (implemented using MPI) that needs to be documented. I'd
I get the error Not implemented. I want to compress a file using 7-Zip
I'm attempting to run TextTransform.exe to generate code using a T4 template file. The
I have implemented a cryptography algorithm using my own code using C#.net , i
My service side code is implemented using Resteasy @GET @Path(/ad-details/{query}) @Produces(application/json) public String getAdDetails(@PathParam(query)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.