Redmine Rest API - file attachment, upload token is not complete - redmine

I'm trying to add an issue with a file attachment but the response token is not complete.
It is the same error as http://www.redmine.org/boards/2/topics/42425 (5 years old question) but there is no response there.
The redmine used is a 3.2.1.stable.
I'm using https://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files to know how to upload files, but when I do a POST to /uploads.json?filename=myFileName, the response is something like {"upload":{"token":"6898."}} The response code is still a 201, so it doesn't seem like there is an error.
The response to the API call should be something like {"upload":{"token":"7167.ed1ccdb093229ca1bd0b043618d88743"}}.
I tried using the partial token returned, to no avail.
Anyone have an idea as to why the token is not okay / how to correct the problem?

For some reason Redmine can't copy uploaded file to persistent (final) location. Maybe there's a lack of disk space, maybe there are some issues with file name. Check your environment.log for
"Saving attachment '#{self.diskfile}' (#{#temp_file.size} bytes)"
when the file is being uploaded. Maybe this will indicate the reason.

In fact, the problem was that the file sent was empty.
This answer may well be of help to someone.

Related

pydrive: Losing file content during upload()

I currently have a 34x22 .xlsx spreadsheet. I am downloading it via pydrive, filling in some of the blank values, and uploading the file back via pydrive. When I upload the file back, all cells with formulas are blank (any cell that starts with =). I have a local copy of the file I want to upload, and it looks fine so I'm pretty sure the issue must be with pydrive.
My code:
def upload_r1masterfile(filename='temp.xlsx'):
"""
Upload a given file to drive as our master file
:param filename: name of local file to upload
:return:
"""
# Get the file we want
master_file = find_r1masterfile()
try:
master_file.SetContentFile(filename)
master_file.Upload()
print 'Master file updated. ' + str(datetime.datetime.now())
except Exception, e:
print "Warning: Something wrong with file R1 Master File."
print str(e)
return e
The only hint I have is that if I add the param={'convert': True} tag to Upload, then there is no loss. However, that means I am now working in google sheets format, and I would rather not do that. Not only because it's not the performed format to work with here, but also because if I try to master_file.GetContentFile(filename) I get the error: No downloadLink/exportLinks for mimetype found in metadata
Any hints? Is there another attribute on upload that I am not aware of?
Thanks!
Robin was able to help me answer this question at the github repository. Both suggested solutions worked:
1) When you upload the file, did you close Excel first? IIRC MS Office writes a lot of the content to a temporary file, so that may explain why some parts are missing. If you tried the non converting upload first, the full file may have been saved to disk between the two tries, and thus the second converting upload attempt worked.
2) GetContentFile takes a second argument called mimetype, which should allow you to download the file. Could you try .GetContentFile(filename, mimetype="application/vnd.ms-excel")? If that mimetype doesn't work as anticipated, there is a great StackOverflow post here which lists a bunch of different types you can try.
Thanks again Robin!

How does one determine the filetype on an AWS S3 hosted file without the extension?

As an example, I'm currently uploading items directly to an S3 bucket using a form. While I was testing, I didn't specify any expected filenames or extensions.
I uploaded a .png which produced this direct link:
https://s3-us-west-2.amazonaws.com/easyhighlighting2/2015-07-271438019663927upload94788
When I place this inside an img tag, it displays on a web page properly.
My question is, without an extension, how would my browser know what type of file it's loading? Inside the bucket, the file's metadata isn't even filled out.
Is there any way to get that file extension, programmatically?
I'm ready to try any clientside methods available; my server-side language is ColdFusion which is somewhat limiting, but I'm open to suggestions for that as well.
Okay, so after some more extensive digging, I found a method of retrieving the file's type that was only added since CF10 was released; that would explain the lack of documentation.
The answer lies in the FileGetMimeType function.
<cfset someVar = "https://s3-us-west-2.amazonaws.com/easyhighlighting2/2015-07-271438019663927upload94788">
<cfset FileType = FileGetMimeType(someVar)>
<cfoutput>#FileType#</cfoutput>
This code would output image/png - which is correct and has worked for every filetype I have tested thus far.
I'm surprised this kind of question hasn't popped up before, but this appears to be the best answer, at least for users of CFML.
Edit:
ColdFusion accomplishes this by either reading the contents of a file, or by trusting its extension. An implicit attribute, 'strict', is used in this function. If true, it reads the file's contents. If false, it uses the provided extension.
True is the default.
Link:
https://wikidocs.adobe.com/wiki/display/coldfusionen/FileGetMimeType
Check the Content-Type HTTP response header returned by Amazon S3.
For example, curl -I https://s3.amazonaws.com/path/to/file fetches only the headers.

How to send srt files over http

I am able to upload videos to Facebook via their Graph API, but unable to upload captions (cc) for those videos. According to their documentation on uploading video captions only the video id, locale, and srt filename must be provided. However, when posting the request
r = requests.post("https://graph.facebook.com/v" + str(self.version) + "/" + path + "?" +
post_data, files={captions_file: open(captions_file, 'rb')})
this is the result:
{"error":{"message":"(#100) Invalid file. Expected file of one of the following types:
application\/octet-stream","type":"OAuthException","code":100}}
My confusion is the documentation specifies the caption file as filename.locale.srt, but the error specifies a file of MIME type application/octet-stream which a .srt file does not apply.
How can a .srt file be sent via application/octet-stream?
I was trying to upload captions for the facebook videos, but the only error I was getting was "(#100) Invalid file. Expected file of one of the following types: application/octet-stream".
So I wrote a ticket in facebook and seems like this is valid bug.
I'm trying to add captions to video, but the only error I'm getting is
"Invalid file. Expected file of one of the following types: application/octet-stream"
The file that I'm using is http://www.apps.bg/filename.bg_BG.srt
Steps to reproduce the bug:
1. Trying to upload captions from api ( /v2.4/video_id/captions )
And the answer that I got was
"We have managed to reproduce this issue and it appears to be a valid
bug. We are assigning this to the appropriate team."
https://developers.facebook.com/bugs/1470577926590877
So we have to wait to fix it - or if someone finds a workaround.
Hope that this will help you.
I had the same problem. The solution is to using file locally ad pass it instead of URL address. Something like this:
curl -i -X POST -F "captions_file=#\"subs.bg_BG.srt\"" https://graph.facebook.com/v2.7/***/captions?access_token...

Editing Files With Flask-Admin

I am using Flask-Admin to provide an admin interface for my web app, and so far everything has gone well. However, I am trying to make it so that the .TXT files can be edited right in the browser.
Reading the docs, I have incorporated the line:
editable_extensions = ('txt')
into my FileAdmin class. However, every time I check the box beside the file and press With Selected -> Edit, I get a "Permission Denied" error. On the contrary, the Rename feature works fine, and I can also click the file name to view the contents.
Does anyone have any idea how to solve this problem, or where I should start looking?
Note that I may very well be missing some required code, as the line above is all I have done with regards to the editing functionality.
EDIT: I have now managed to get:
Unexpected error while reading from filename.txt
This file cannot be edited for now.
Never mind, this was fixed in an update. For those curious as to what the issue was, the edit() function in fileadmin.py was opening the file as 'r', rather than 'rb'. This caused the error:
'str' object has no attribute 'decode'
which consequently produced in error in the very end.

client cert and clientcertpassword in cfhttp

Recently I am done with the SSL certification installation procedure in the Coldfusion Truststore, I'm getting Attribute Validation error now which clearly states that I need to have cfhttp in my code. I understood that. So,I'll have to use cfhttp something like the following: method = "post", clientCert = ?? and clientCetPassword = ?? result = "xyz"
I came across some posts (forums.adobe.com/message/800318) and there they have mentioned that clientcert should include file with format, .pkcs ? If yes, then, I'm wondering from where should I bring this file and am I following the correct procedure? Is it the same file that I downloaded in the DER format? Please throw some light on this.
Does anyone know any good source where I can read about sending clientCert and clientcertPassword related stuff? Adobe docs aren't much informative for me.
Thanks
P.S: The SSL instalaltion work I did is mentioned at one of my previous post. Please take a look.
Getting Unable to read WSDL error