PDA

View Full Version : Problem fetching attachments with dekiscript



jgable
09-02-2008, 11:49 PM
Here is what I am doing to test this problem

AAAAAAAAAAAAAAAAAAAAAAAAAAAAA

{{ web.html('<pre>' .. web.text(page.files["addCSS.xml"].uri) .. '"</pre>' )}}

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

{{page.files}}

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

{{ page.files["addCSS.xml"].uri }}

DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

{{
var files = map.values(page.files);
if(#files > 0) {
syntax.xml(web.text(files["addCSS.xml"].uri))
} else {
"no file(s) attached"
}
}}



And here are the results I get back

AAAAAAAAAAAAAAAAAAAAAAAAAAAAA


(unable to fetch text document from uri [401])"
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

{ "96x128.bmp" : "local://d4b0d799a0844ad49811501c7293b3f1/deki/$file#%5b+44+%5d", "AddCSS.xml" : "local://d4b0d799a0844ad49811501c7293b3f1/deki/$file#%5b+54+%5d" }

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

http://vpwiki.domain.com/@api/deki/files/54/=AddCSS.xml

DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD


the last test is copied from here http://wiki.developer.mindtouch.com/MindTouch_Deki/DekiScript/FAQ/How_do_I..._Write_my_first_extension_in_DekiScript %3f and returns an empty syntax block.

I am running 8.05.2b in vmware

neilw
09-04-2008, 08:35 PM
You're already 99% of the way there. Your third example correctly returns the URI of the attachment, and that is the way to get the attachment contents. All you have to do is use one of the web.*() Dekiscript functions to fetch the file and do what you want with it. For instance:

{{ syntax.xml(web.text(page.files["addCSS.xml"].uri)) }}
will display the XML file. This example is basically taken from the web.text() documentation (http://wiki.developer.mindtouch.com/DekiScript/Reference/DekiScript_Functions_and_Variables/Web.Text), substituting the computed URI of the attachment.

SteveB
09-04-2008, 11:21 PM
Actually, the 401 error indicates that the attachment is on a protected page or the wiki is private. Either way, deki cannot retrieve a document from a protected page like that for security reasons.

jgable
09-05-2008, 02:05 AM
Steve,
Are you saying that if I am on a page I cannot get the attachments through dekiscript?
Doesn't dekiscript use the credentials for the person that is running it?

neilw
09-05-2008, 01:47 PM
First off, my apologies for missing the correct meaning of the first example.

When you access the API via a web.*() call, even though it's Dekiscript you're not really going through the wiki, just a standard web fetch, and wiki credentials are not maintained. The wiki.*() calls work within the wiki and *do* maintain credentials. That is why you can use wiki.page(p) to fetch a restricted page, but web.xml(p.uri) will fail.

Steve can give the final word (as always), but as far as I can tell there's no documented at present to fetch an attachment's contents from within the wiki. This would be a nice feature improvement. Could be accessible from within the files variable (files["name"].contents), or wiki.file() or something like that. Just a thought.

SteveB
09-05-2008, 06:17 PM
neilw is correct. We would need to add a function like wiki.getfiles to pass along the user's credentials. Please file a bug on it, thanks!

jgable
09-05-2008, 06:35 PM
I loged the bug