Equalhand Objective C Code
I am trying to upload videos through php in objective c. I have done the same for android but in objective c the files are not getting uploaded. The entire call to my php is: - (IB
Solution 1:
Check the NSFileHandle
class and the readDataOfLength
method. You can also check the attributesOfItemAtPath:error
method of NSFileManager
to get the file size.
Solution 2:
Why do you create such a big buffer? The data is read in smaller chunks anyway.
InputStream in; //FileInputStream
OutputStream out; //DataOutputStreambyte[] buffer = newbyte[10 * 1024]; //or anything bigger you wantint bytesRead;
while ((bytesRead = in.read(buffer, 0, buffer.length) > 0)) {
out.write(buffer, 0, bytesRead);
}
In objective-c:
#define BUFFER_SIZE 10 * 1024NSFileHandle* fileHandle; //file handleNSMutableData* out; //data bufferchar buffer[BUFFER_SIZE];
ssize_t bytesRead;
while ((bytesRead = read([fileHandle fileDescriptor], buffer, BUFFER_SIZE) > 0) {
[out appendBytes:buffer length:(NSUInteger) bytesRead];
}
Of course, you can also use other methods on NSFileHandle (see Marcelo Alves' answer). Anyway, to read entire file, don't waste time reading file size, it's not necessary.
Post a Comment for "Equalhand Objective C Code"