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 8820563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:38:24+00:00 2026-06-14T05:38:24+00:00

I’m trying to upload a large video from iphone to a web server that

  • 0

I’m trying to upload a large video from iphone to a web server that has php script.

I’m using NSInputStream to get file video chunks and I’m creating a request(POST) on each traversal of the

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode

method, with the read data passed as parameter.

Here is the code I’m using to get chunks of data

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode 
{
switch(eventCode) 
{
    case NSStreamEventHasBytesAvailable:
    {
        NSMutableData *dataSlice;

        uint8_t buf[1048576];
        unsigned int len = 0;
        len = [(NSInputStream *)stream read:buf maxLength:1048576];
        if(len) 
        {
            dataSlice = [NSMutableData dataWithBytes:(const void *)buf length:len];


            NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:folderNameForUpload, kFolderName,
                                           @"abcd.MOV", kFileName,
                                           @"MOV", kFileType,
                                           nil];
            MKNetworkOperation *op = [self.networkEngine operationWithPath:@"upload.php" params:params httpMethod:@"POST"];

            [op addData:dataSlice forKey: @"file"
                             mimeType: @"image/mov"
                             fileName: @"abcd"];

            [op onCompletion:^(MKNetworkOperation *completedOperation) {

            } onError:^(NSError *error) {

            }];

            [[WebRequest sharedInstance].networkEngine enqueueOperation: op];


        }
        else 
        {
            NSLog(@"NO MORE BUFFER!");
        }
        break;
    }


    case NSStreamEventEndEncountered:
    {
        [stream close];
        [stream removeFromRunLoop:[NSRunLoop currentRunLoop]
                          forMode:NSDefaultRunLoopMode];
        [stream release];
        stream = nil;
        break;
    }
}
}

It is sending the data to the server, and I’m able to write the chunks into a file. But, the problem is that, if there are more than one chunk, the file will become corrupted and I’m not able to open the video file.

I checked the file size on both server and client, and both are exactly same.

Below is the php script, I’m using to merge video file chunks.

        $tmp_file = $_FILES['file']['tmp_name'];

        $write_handle = fopen($fileURL, "ab+");
        $read_handle = fopen($tmp_file, "rb");

        $contents = fread($read_handle, filesize($tmp_file));
        fwrite($write_handle, $contents);

        fclose($write_handle);
        fclose($read_handle);

What Am I doing wrong here?, Please help!

I’m stuck over this problem!!

Thanks in Advance,

Suraj

  • 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-14T05:38:25+00:00Added an answer on June 14, 2026 at 5:38 am

    I got the problem myself guys. Actually, I was sending different chunks of video at the same time. And the problem was arising because the later chunks of video reached server before the first chunk of video.

    I solved the problem by sending second chunk of video only after the first chunk is reached web server and the response is got at the client side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.