How to check progress when uploading a file to QBContent? - quickblox

We're uploading files to QB Content using QB Content TUploadFile and we used setProgress to check the progress of the upload but we received random values ranging from 0 to 0.5 multiple times.
What is the right way to check the progress of an upload to QB Content?
[QBContent TUploadFile:imageData fileName:imageName contentType:#"image/png" isPublic:YES delegate:self context:(__bridge void*)context];
- (void)setProgress:(float)progress
{
NSLog(#"progress: %f", progress);
}

Related

How to display an image in expo-av after video stopped playing?

I'm new to RN, I'm trying to create a video player using expo-av. I want to display an image once the video stopped playing. I've looked at the documentation which has VideoThumbnail, but
per my understanding, that generates a thumbnail from the video. I've a separate Jpeg file that I want to display after video ends.
How can I do that?
Update 1:
Expo-av has playbackStatus.didJustFinish. Next step is to display an image in this callback function.
const onPlaybackStatusUpdate = useCallback(() => {
if (playbackStatus.didJustFinish) {
// Show image
}
},[playbackStatus]);

Video streaming - dealing with header 206 (php to HTML5)

As usual, it never works for me...
I try to stream video and I'm doing very well with the code below:
function send_back_video($video_path)
{
ob_clean();
$mime = "application/octet-stream"; // The MIME type of the file, this should be replaced with your own.
$size = filesize($video_path); // The size of the file
// Send the content type header
header('Content-type: ' . $mime);
// Check if it's a HTTP range request
if(isset($_SERVER['HTTP_RANGE']))
{
// Parse the range header to get the byte offset
$ranges = array_map(
'intval', // Parse the parts into integer
explode(
'-', // The range separator
substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header
)
);
// If the last range param is empty, it means the EOF (End of File)
if(!$ranges[1]){
$ranges[1] = $size - 1;
}
// Send the appropriate headers
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range
// Send the ranges we offered
header(
sprintf(
'Content-Range: bytes %d-%d/%d', // The header format
$ranges[0], // The start range
$ranges[1], // The end range
$size // Total size of the file
)
);
// It's time to output the file
$f = fopen($video_path, 'rb'); // Open the file in binary mode
$chunkSize = 8192; // The size of each chunk to output
// Seek to the requested start range
fseek($f, $ranges[0]);
// Start outputting the data
while(true)
{
// Check if we have outputted all the data requested
if(ftell($f) >= $ranges[1])
{
break;
}
// Output the data
echo fread($f, $chunkSize);
// Flush the buffer immediately
#ob_flush();
flush();
}
}
else {
// It's not a range request, output the file anyway
header('Content-Length: ' . $size);
// Read the file
#readfile($file);
// and flush the buffer
#ob_flush();
flush();
}
}
"So if it works, what do you want?" - you might ask..
As I stated before, the code does a very good job, BUT there is 1 issue.
If I start to play video, php sends header('HTTP/1.1 206 Partial Content') and this (video) request stays open till EOF, what means, I am FORCED to download entire video even if don't want to (let's say I'm clicking on the next video).
My JS removes video tag (this should ABORT request) and creates new video tag with new link. ABORT part is not happening.
Here you can see GET the example:
1st - initial video get
2nd - play button pressed
3rd - navigate away - new DOM item created and waiting to appear.
So what I'm looking for, is some option to close the connection on navigate away.
I saw youtube does many GETs. As I understand every GET brings new "chunk" when previous "chunk" close to end. It's very good option, but it cancels buffering and I want to be able to buffer video.
P.S.
For sure I'm doing something wrong, I just can't see what.
P.P.S.
I'm not the author of the code.

Rotativa pdf doesn't work when published to Azure Server

I have a web app with Asp.net MVC 5 and I used Rotativa for the pdf.
Rotativa doesn't work when published to Azure Server but it works on my local computer.
It is giving bellow error
500 - THE REQUEST TIMED OUT.
The web server failed to respond within the specified time.
Bellow is my code.
public ActionResult DoPdf(int id)
{
return new ActionAsPdf("PrintMyPdf", new { id = id }) { FileName = string.Format("Demo_{0}.pdf", id) };
}
Here is a list of frameworks and scenarios that have been found to be not be usable due to the restrictions byAzure Web App sandbox
https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks
Please suggest how can I do PDF of my HTML view in MVC 5?
I suggest you to use the HTML to PDF for Azure Websites from EvoPdf. You have full control over the HTML to PDF Azure cloud service because you are the owner of the service and you don't have to worry about thing like the security of the data you send for conversion. The code you are using in your website looks like below:
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Get the server IP and port
String serverIP = textBoxServerIP.Text;
uint serverPort = uint.Parse(textBoxServerPort.Text);
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);
// Set optional service password
if (textBoxServicePassword.Text.Length > 0)
htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
// Set HTML Viewer width in pixels which is the equivalent in converter of the browser window width
htmlToPdfConverter.HtmlViewerWidth = int.Parse(htmlViewerWidthTextBox.Text);
// Set HTML viewer height in pixels to convert the top part of a HTML page
// Leave it not set to convert the entire HTML
if (htmlViewerHeightTextBox.Text.Length > 0)
htmlToPdfConverter.HtmlViewerHeight = int.Parse(htmlViewerHeightTextBox.Text);
// Set PDF page size which can be a predefined size like A4 or a custom size in points
// Leave it not set to have a default A4 PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize();
// Set PDF page orientation to Portrait or Landscape
// Leave it not set to have a default Portrait orientation for PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation();
// Set the maximum time in seconds to wait for HTML page to be loaded
// Leave it not set for a default 60 seconds maximum wait time
htmlToPdfConverter.NavigationTimeout = int.Parse(navigationTimeoutTextBox.Text);
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
if (conversionDelayTextBox.Text.Length > 0)
htmlToPdfConverter.ConversionDelay = int.Parse(conversionDelayTextBox.Text);
// The buffer to receive the generated PDF document
byte[] outPdfBuffer = null;
if (convertUrlRadioButton.Checked)
{
string url = urlTextBox.Text;
// Convert the HTML page given by an URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
}
else
{
string htmlString = htmlStringTextBox.Text;
string baseUrl = baseUrlTextBox.Text;
// Convert a HTML string with a base URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertHtml(htmlString, baseUrl);
}
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("{0}; filename=Getting_Started.pdf; size={1}",
openInlineCheckBox.Checked ? "inline" : "attachment", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}

How to upload photo with Rubymotion?

I am building an iOS app using Rubymotion.
I need to let the user snap a photo with the camera and then upload it to a Rails 3 backend (with Paperclip) using the BubbleWrap Http module (or any better?).
How can I do this?
This is my code:
controller = UIImagePickerController.alloc.init
controller.sourceType = UIImagePickerControllerSourceTypeCamera
controller.mediaTypes = [KUTTypeImage]
controller.allowsEditing = true
controller.delegate = self
self.navigationController.presentModalViewController(controller, animated:true)
This I use after taking the shot:
metadata = info.objectForKey(UIImagePickerControllerMediaMetadata)
the_image = info.objectForKey(UIImagePickerControllerOriginalImage)
image = view.viewWithTag 3
image.image = the_image
picker.dismissModalViewControllerAnimated(true)
This is my upload code:
data = {access_token: TOKEN, id: task, image: image}
BubbleWrap::HTTP.get("#{URL}#{project}/message", {payload: data}) do |response|
if response.ok?
json = BubbleWrap::JSON.parse(response.body)
if json['total'] > 0
infos = json['taskinfos'].map {|ej| self.from_json(ej["taskinfo"])}
block.call(true, infos)
else
block.call(false, nil)
end
else
block.call(false, nil)
end
end
Uploading images should be done via a POST request and not a GET request like you have done. Most web servers have a limit to how big a GET request can be, and it is usually 8k, read here for more info maximum length of HTTP GET request? , so it's not suitable for images.
Play around with bubble motion and look at the requests in the log files on the server to see what comes out. Try to make the request look like a request made from within rails itself, ie from a web page where you upload to the the controller.
So you could change the request to POST and let people know what error messages you get.

Can't Save Image Blob

I am trying to save an image from the photo gallery to local storage so that I can load the image up across application sessions. Once the user is done selecting the image, the following logic is executed. On the simulator I see the error message is written out to the log. Even though I am seeing the error message I think the image is still saved in the simulato because when I restart the application I am able to load the saved image. When I run this on the device though, I still get the error message you see in the code below and the default background is loaded which indicates the write was not successful.
Can anyone see what I am doing wrong and why the image won't save successfully?
var image = i.media.imageAsResized(width, height);
backgroundImage.image = image;
function SaveBackgroundImage(image)
{
var file = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,W.CUSTOM_BACKGROUND);
if(file.write(image, false))
{
W.analytics.remoteLog('Success Saving Background Image');
}
else
{
W.analytics.remoteLog('Error Saving Background Image');
}
file = null;
}
Try this Code:
var parent = Titanium.Filesystem.getApplicationDataDirectory();
var f = Titanium.Filesystem.getFile(parent, 'image_name.png');
f.write(image);
Ti.API.info(f.nativePath); // it will return the native path of image
In your code i thing you are not giving the type of the image (png/jpeg) thats why your getting error.