Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF

TOPIC:

HTTP Streaming 9 years 9 months ago #6623

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
I will re-test this, but our files are hosted on Amazon S3 which does support range headers...

I'll test again and post back here with the results

thanks!

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6635

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
Hi there, I have tested with the PDF you suggested and I am afraid that I see it downloading all the blocks again before attempting to show the user the PDF.

I have put logging into PDFHttpStream as follows:
-(void)init_lentgh
{
    NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:m_url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60.0];
	NSHTTPURLResponse *lenResponse;
    
    NSLog(@"START HEAD request to: %@", m_url);
    
	[urlRequest setHTTPMethod:@"HEAD"];
	[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&lenResponse error:nil];
	long len = [[[lenResponse allHeaderFields] objectForKey:@"Content-Length"] intValue];
    NSLog(@"END HEAD request to: %@ size: %ld", m_url, len);
	m_total = len;
	if( len > 0 )
	{
        NSLog(@"START write file at path: %@", m_cache_path);
	    m_file = fopen([m_cache_path UTF8String], "wb+");//read-write cached file.
	    unsigned char tmp[4096];
	    memset( tmp, 0, 4096 );
	    int cur = 0;
	    while( cur < m_total - 4095 )
	    {
	    	fwrite( tmp, 1, 4096, m_file );
	    	cur += 4096;
	    }
	    fwrite( tmp, 1, m_total - cur, m_file );
	    m_block_cnt = (m_total + BLOCK_SIZE - 1)/BLOCK_SIZE;
	    m_block_flags = (unsigned char *)malloc(m_block_cnt * sizeof(unsigned char));
	    memset( m_block_flags, 0, m_block_cnt * sizeof(unsigned char) );//init all flags.
        NSLog(@"END write file at path: %@", m_cache_path);
	}
}

and
-(bool)download_blocks :(int) start :(int)end
{
    NSLog(@"START Download blocks: %d to %d", start, end);
    
	bool ret = true;
	while( start < end )
	{
		while( start < end && m_block_flags[start] ) start++;
		int prev = start;
		while( start < end && !m_block_flags[start] ) start++;
		if( start > prev )
		{
			int len = 0;
			int off = prev * BLOCK_SIZE;
		    len = m_total - off;
		    if( len > (start - prev) * BLOCK_SIZE )
		    	len = (start - prev) * BLOCK_SIZE;

		    NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:m_url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60 + 30 * (start - prev - 1)];
		    NSHTTPURLResponse *urlResponse;
		    [urlRequest setHTTPMethod:@"GET"];
		    NSString *hval = [NSString stringWithFormat:@"bytes=%i-%i", off, off + len];
		    [urlRequest setValue:hval forHTTPHeaderField:@"Range"];
		    NSError *err;
            NSLog(@"Starting synchronous request to %@ with byte range: %d-%d", m_url, off, off + len);
		    NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&urlResponse error:&err];
		    if(responseData != NULL)
		   	{
		        memset( m_block_flags + prev, 1, start - prev );
			    fseek( m_file, off, SEEK_SET );
	            fwrite( [responseData bytes], 1, len, m_file );
		    }
		    else
		    	ret = false;
		}
	}
    NSLog(@"END Download blocks: %d to %d", start, end);
	return ret;
}

and then when I perform a call to PDFHttpStream open, I see a LOT of output to the console as below:
2014-07-14 10:38:25.958 talis[25828:90b] START HEAD request to: http://www.radaee.com/files/test.pdf
2014-07-14 10:38:26.194 talis[25828:90b] END HEAD request to: http://www.radaee.com/files/test.pdf size: 2967267
2014-07-14 10:38:26.195 talis[25828:90b] START write file at path: /Users/russellhill/Library/Application Support/iPhone Simulator/7.1/Applications/DD59FCCA-F587-499D-8581-06A6AC925D5D/tmp/test.pdf
2014-07-14 10:38:26.198 talis[25828:90b] END write file at path: /Users/russellhill/Library/Application Support/iPhone Simulator/7.1/Applications/DD59FCCA-F587-499D-8581-06A6AC925D5D/tmp/test.pdf
2014-07-14 10:38:26.198 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.198 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.199 talis[25828:90b] Starting synchronous request to http://www.radaee.com/files/test.pdf with byte range: 0-8192
2014-07-14 10:38:26.432 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.432 talis[25828:90b] END read: 2000
2014-07-14 10:38:26.432 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.433 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.433 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.433 talis[25828:90b] END read: 2000
2014-07-14 10:38:26.433 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.433 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.433 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.434 talis[25828:90b] END read: 2116
2014-07-14 10:38:26.434 talis[25828:90b] START read: 70
2014-07-14 10:38:26.434 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.434 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.434 talis[25828:90b] END read: 452
2014-07-14 10:38:26.434 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.434 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.435 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.435 talis[25828:90b] END read: 3620
2014-07-14 10:38:26.435 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.435 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.435 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.435 talis[25828:90b] END read: 2502
2014-07-14 10:38:26.435 talis[25828:90b] START read: 1024
2014-07-14 10:38:26.436 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.436 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.436 talis[25828:90b] END read: 1601
2014-07-14 10:38:26.436 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.436 talis[25828:90b] START Download blocks: 0 to 1
2014-07-14 10:38:26.436 talis[25828:90b] END Download blocks: 1 to 1
2014-07-14 10:38:26.436 talis[25828:90b] END read: 3994
2014-07-14 10:38:26.436 talis[25828:90b] START read: 2000
2014-07-14 10:38:26.437 talis[25828:90b] START Download blocks: 7 to 8
2014-07-14 10:38:26.437 talis[25828:90b] Starting synchronous request to http://www.radaee.com/files/test.pdf with byte range: 57344-65536

This is just the first page or so from the log. The log is filled with the above as it requests more blocks with different byte ranges from the server. Only when all the blocks have been requested does the PDF open.

Is there anything else you can suggest?

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6688

  • stronglee
  • stronglee's Avatar
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 93
  • Thank you received: 2
There release a new version,try new version.
The url test.pdf return pdf length takes a lot time, I'm founding the reason

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum