invalid encoding when uploading an image to rails using javascript - ajax

I'm using qqfileupload (http://valums.com/ajax-upload/) to create a single drag & drop image upload interface.
The request is being sent to rails, and my rails console is returning
!! Unexpected error while processing request: invalid %-encoding (����JFIFdd��Ducky��Adobed)
which I assume is rails attempting to read the file.
I set my controller to output
return render :text => params
thinking that I could look at what the server was recieving, but I only get the Unexpected error again, which to me says that Rails is hitting this error before getting to the controller.
The params from the javascript console shows
http://localhost:3000/users?qqfile=me.jpg&first_name=&last_name=
the first and last fields are supposed to be blanks.

I stared following this tutorial http://css-tricks.com/ajax-image-uploading/, which looked very similar to the case I was already using, and it lead to this download script http://valums.com/ajax-upload/, which is almost identical to the one I had before, but somehow is slightly different and doesn't return the error above.
Hopefully this helps somebody out.

Related

Cant figure out, why i get a 403

i try to setup the youtube api but i get a 403.
I tried to setup several times- without success.
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=-DIJvggBrg8&key=xyz
Maybe someone is able to help me or even login to the console for a setup?
The 403 error by itself is not of immediate use. Its attached error code (as I already pointed out above) sheds light on the things that happened.
The API responds to any query you make with a text (that is structured in JSON format). That response text contains the needed error code.
I suggest you to proceed with the following steps:
delete the old API key (right now it is still accessible!);
create a new API key and
run your API query using the new key and then post here the API response text.
Note that I checked the video -DIJvggBrg8 to which your query refers to with my own API key and got no error but a JSON text describing the video.

Classic ASP Error Handling: Calling a function after an error?

I do maintenance on a classic ASP website that basically has no error handling at all yet. So users see any error message that comes across... Instead, I would like my code to be able to catch any potential error and then fire off an email before redirecting the user to a more friendly error-page.
This website is rather large, and every webpage comes with the same include file at the beginning... So ideally, I would like to set an error handler from the beginning of this include file. I haven't had any luck finding a way to do this without having to go through every page individually having error handling happen at the end of the script... Is there a possible way to code something like this from the include file?:
' Include file contents:
Function MyHandler()
'Code for triggering email goes here
response.redirect "ErrorPage.asp"
End Function
On Error call MyHandler()
Thanks in advance!
I suggest to use Custom Error Pages in IIS (Web Server), if you have access to those. You can redirect different types of errors to different scripts if you like or point them all to a single one and have there the logic for all error codes.
You can catch common errors there and maybe redirect the user to a alternative page/site, or return a specific error message.. I would suggest to use the custom error page also to log the error and some information from the session (e.g. form submit data, query strings, referrer URLs, cookies etc.) in a database and/or send a notification email to some service account to identify specific issues that are occurring and then also have something to go on to actually fix the cause of many of the errors.

Sinatra-Synchrony is causing HttpProtocolException: HTTP-headers - are expected Error for some users

I have a webapp that updates data in Pardot through one of their API's.
The webapp is coded with Sinatra. The user adds the api url and a csv file with the data that needs to be updated in a form and hits submit. The code parses the csv data and sends it to the url that was provided. The back end server is Windows Server 2008 R2 with IIS 7.5 and HeliconZoo.
Because of performance issues Helicon tech support pointed me to Sinatra::Synchrony and I decided to implement it.
I tested it on multiple different computers with different OS's and browsers and everything works good. Performance was noticeably faster when more then one computer was connected and had submitted the form.
The problem I have is that some users keep getting this error after every time they submit the form:
Error
Helicon Zoo module has caught up an error. Please see the details below.
Worker Status
%WorkerStatus%
Windows error
%WindowsError%
Internal module error
message: HTTP-headers - are expected
job: JobHttp[#3] - /
transportStatus:Online
getErrorMessage:
RAW output bytes:0
RAW output Begin
Empty stderr
End
type: ZooException
file: JobHttp.cpp
line: 266
version: 1.1.57.268
Even though they get this error the data was sent to Pardot successfully.
Here is an entry from the ZooError.log file:
[10/24/2012 10:44:01] HttpProtocolException: HTTP-headers - are expected
job: JobHttp[#212] - /
transportStatus:Online
getErrorMessage:
RAW output bytes:0
RAW output Begin
Empty stderr
End
Where do I even start to troubleshoot this error?
Neil. I'm from Helicon Tech and will try to help you.
Please check the log of your Sinatra application, as according to our logs Sinatra responded with empty response which is not good.
It can be some issue in Zoo, so if you could provide some test application and instructions on how to reproduce such behavior to our helpdesk, we would try to detect and fix it.
I want to thank Tony for offering to help but this error didn't have anything to do with Helicon Zoo. The errors that were displayed on the screen from Zoo weren't any help but this ended up being an issue with my own code.
I was sending data to Pardot that came from a csv file. The users where creating the .csv files from excel by copying from one excel sheet to the other. By doing this excel was copying a bunch of blank lines and these blank lines were then saved into the csv file.
So...once I checked for blank rows in the csv file:
if !row.empty?
I stopped getting the error.

Codeigniter global error override

Is there a way in Codeigniter to override global errors. For instance if an DB error or PHP critical occurs it wont show the error itself but something like 'Our admin guy is fixing the issue' and the error is just logged and emailed.
Codeigniter lets you handle error messages your way, depending on the HTTP status.
Refer to this documentation on error handling
In addition to #Pos5e5s3dFr3ak's answer, you should handle as many errors as you can manually. For example, if you have a database error, your code should acknowledge (or 'catch') it and perhaps load the appropriate view, or pass it onto a library that will log an email the fault, instead of displaying the intended result.
This method can be used as an alternative, or as an addition to the original answer - sometimes you need not locate the error just by its HTTP response Status Code.
As an example, you may find that the database engine in use is down. If this is the case (you would have to determine if it is indeed down - ie. you are not getting the desired response), you would pass the user on to example.com/error/database, for example.

Problems attempting to upload image to Twitter via POST in Sinatra

I'm using Sinatra 1.2.6 in Ruby 1.8.7 and I have something like a Twitter client that I'm writing. I am using the Twitter gem version 1.7.2 written by John Nunemaker. For database ORM I'm using Sequel 3.29.0.
Overall, things are working great. I've got a good Oauth sequence working and any user who goes through the Oauth process can post Tweets to my application.
I cannot however for the life of me get media upload working using update_with_media. I'm trying to upload a multi-part octet-stream image file, keep it in memory and then give it to Twitter.
post '/file_upload' do
user_name = params[:user]
if params[:action] == "FILE-UPLOAD"
unless params[:name].match(/\.jpg|png|jpeg/).nil?
#Assume these 3 lines work, and properly authorize to Twitter
current_user = User[:user_name => user_name, :current_account => "1"]
client = current_user.authorize_to_twitter #Handles the Oauth keys/process
client.update("Text status updates work properly")
#Something incorrect is happening in the next two lines.
#I'm either handling the file upload wrong, or posting wrong to Twitter
datafile = params[:file]
client.update_with_media("File upload from Skype: ", datafile)
return "File uploaded ok"
end
end
end
Yet, when I try this, I'm getting:
Twitter::Unauthorized - POST https://upload.twitter.com/1/statuses/update_with_media.json: 401: Could not authenticate with OAuth.
Its saying the line causing this error is the client.update_with_media line.
I am trying to use Rack::RawUpload, but I don't know if I'm using it incorrectly. If I don't need to use it I won't, but I'm just currently stuck. The only thing outside of this code snippet that's using it is this at the top of my code:
require 'rack/raw_upload'
use Rack::RawUpload
Any help on this would be massively appreciated. I've tried messing around with Tempfile.new() as well, but that didn't seem to help much, and I was either getting 401 or 403 errors. I'm fairly new to Ruby, so being as explicit as possible about changes needed would be really helpful.
I should note that I'd like to avoid putting the file on the filesystem if possible. I'm really just passing along the upload here, and I never need access in my scenario to the file on-disk afterward. Keeping the files in-memory is much preferred.
You need to check how your library HTTP headers are setup and logically connected to the POST method you have written here. The thing is that for upload_with_media, twitter api in this gem version requires you to use http://upload.twitter.com upload endpoint instead of the default api endpoint.
The gem may be forcing the api site so while the OAuth based status update works fine, it crashes when you try it with an image. You will need to check the gem documentation to figure out how to force the upload twitter site into the HTTP headers for this method.
Alternatively, consider updating to the latest twitter gem. This is what I got from http://rdoc.info/gems/twitter
The Twitter::API#update_with_media method no longer uses the custom upload.twitter.com endpoint, so media_endpoint configuration has been removed. Likewise, the Twitter::API#search method no longer uses the custom search.twitter.com endpoint, so search_endpoint configuration has also been removed.

Resources