Uploading to exist-db (controller issue?) - exist-db

All of the files are available at http://gist.github.com/tonyahowe -- page.html, app.xql, upload.html, and form1.html. The app:upload function in appxql is at line 378.
I am trying to add an upload feature to my application here (http://nic.cerosia.org) and have been able to get the upload to work without integrating it into the whole application. Once I integrate it, I get a 400 error message, included below. I think the problem might be a controller issue, but I'm not sure?
I have added a simple link from the index to upload.html page, as follows:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="main">
<form enctype="multipart/form-data" method="post" action="form1.html">
<fieldset>
<legend>Upload Document:</legend>
<input type="file" name="file"/>
<button id="f-btn-upload" name="f-btn-upload" value="true" type="submit" class="btn btn-danger">Upload</button>
</fieldset>
</form>
</div>
That sends the upload file to form1.html, which basically figures out what to do with different form actions (it works with the first two options):
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="main">
<div/>
<!-- if a query search -->
<div data-template="templates:if-parameter-set" data-template-param="query">
<div data-template="templates:include" data-template-path="search.html" class="col-md-12"/>
</div>
<!-- if a coursepack search -->
<div data-template="templates:if-parameter-set" data-template-param="f-btn-coursepack">
<div data-template="templates:include" data-template-path="coursepack.html" class="col-md-12"/>
</div>
<!-- if an upload -->
<div data-template="templates:if-parameter-set" data-template-param="f-btn-upload">
<div data-template="templates:include" data-template-path="success.html" class="col-md-12"/>
<div data-template="app:upload"/>
</div>
</div>
The app:upload is here:
declare function app:upload($node as node(), $model as map(*), $type as xs:string?) {
let $collection := '/db/apps/NiC/inReview/'
let $filename := request:get-uploaded-file-name('file')
(: make sure you use the right user permissions that has write access to this collection :)
let $login := xmldb:login($collection, 'public', 'public')
let $store := xmldb:store($collection, $filename, request:get-uploaded-file-data('file'))
return
<results>
<message>File {$filename} has been stored at collection={$collection}.</message>
</results>
};
I keep getting an error that I think has something to do with the controller, but I'm not sure. Can anyone help me figure out where the problem is? It may also be a templating issue?
Here's the error:
HTTP ERROR 400
Problem accessing /exist/apps/NiC/works/form1.html. Reason:
SAX exception while parsing request: Content is not allowed in prolog.

I don't know for sure, but I wonder if it is an issue with the templating framework reading the data from the request body and then it not being available in your app:upload function.
I wonder if we could test this, perhaps instead of checking for f-btn-upload which will be in the body of the HTTP request, you could instead check for a query-string parameter. If you change your form in the upload.html page to be like this:
<form enctype="multipart/form-data" method="post" action="form1.html?do-upload=true">
and the switch in your form1.html to be like this:
<div data-template="templates:if-parameter-set" data-template-param="do-upload">
Does that help you at all?

Related

ePub3 eBook - Allowing users to enter the page they want to go to

I am currently working on an ePubv3 book and have run into a problem. I'm using Sigil as the IDE. My goal is to allow the reader to type in the page number that they would like to jump to. Here is my code:
<head>
<title>testing</title>
<script>
function goToPage() {
var pageNumber = document.getElementById('page-number').value;
</script>
</head>
<body>
<p> </p>
<form method="post" onsubmit="goToPage" action="#">
<label for="page-number">Enter page number:</label>
<input type="text" id="page-number" name="page-number"><BR>
<p class="submit">
<input type="submit" value="Go to page"></input>
</p>
</form>
</body>
</html>
I have tried a few different ways. With and without the "class" option, changing the javascript. But haven't been able to get it to work.
Would someone please tell me what I am doing wrong?
Thank you
The goal is to allow the reader to type in a number to go to that page. An example being that they want to go to page 33 (from say page 2). They would just type in 33 in the input box and go to that page.

Extension doesn´t work after deleted Cache

i have a problem with one of my extensions i created with Extensionbuilder.
After i deleted the Cache there is no content anymore!
<f:flashMessages renderMode="div"/>
<div class="tx-camping-list">
<f:for each="{offers}" as="offer" iteration="it">
<div class="content-list-item">
<div class="contentLeft floatLeft">
<f:render partial="BaseItem/ListImages" arguments="{item:offer}" />
<div class="wrap-right floatRight">
<h3>
<f:link.action arguments="{offer:offer}">
<f:format.raw>{offer.names}</f:format.raw>
</f:link.action>
</h3>
<h4>
<f:format.raw>{offer.teaser}</f:format.raw>
</h4>
<div class="description"><f:format.crop maxCharacters="240"><f:format.html>{offer.description}</f:format.html></f:format.crop>
<p>
<f:link.action arguments="{offer:offer}">
<f:translate key="read_more" default="Read more" /> >
</f:link.action>
</p>
</div>
</div>
</div>
<div class="roomPrice floatRight">
<f:render partial="Price/ListPriceBox" arguments="{item:offer}" />
<f:render partial="BaseItem/Button" arguments="{item:offer,type:'Offer'}"/>
</div>
<div class="clearFloat"></div>
</div>
</f:for>
</div>
The image, {offer.names}, {offer.teaser} etc. is NULL, BUT the link {offer:offer} is working
When i reload the page the first time after i deleted the Cache i get the error:
The argument “each” was registered with type “array”, but is of type “string” in view helper
After a reload everything works fine except this plugin!
Maybe some of you can help me
Thanks
Use <f:debug> to find out what you real values are. You cannot loop over a string. Most likely, you are mistaken over your nesting level of your object.
Also do not use <f:format.raw> unless you already ensured, that the contend is htmlspecialchar'd. Otherwise you loose the XSS protection.
This can just fix the error if its caused by a missing reference on records
You could try to add the following line of code to your setup.ts (or .txt; depending on configuration and personal preferences):
File: slider/Configuration/TypoScript/setup.ts:
plugin.tx_slider.persistence.storagePid = 15
Note: replace tx_slider with your extensionkey and the 15 with the pagenumber where your records (in this case your offer-records) are located

WebAPI Knockout JS Image Binding

I am using Knockoutjs to render a user profile page. For which I am calling a Web API service which returns User details with its Profile Picture.
var MessageFrom = {
FromUserProfileId: self.FromUserProfileId,
FromUserName: self.FromUserName,
FromUserPictURL: self.FromUserPictURL
}
<div id="comments" class="comments" data-bind="with: viewModel">
<div class="comment clearfix" data-bind="foreach: Messages">
<div class="comment-avatar">
<img class="img-circle" data-bind="attr:{'src': FromUserPictURL}" alt="avatar">
</div>
<header>
<h3 data-bind="text: FromUserName"></h3>
<div class="comment-meta"><p data-bind="text: moment(DatePosted).format('LLL')"></p> </div>
</header>
<div class="comment-content">
<div class="comment-body clearfix">
<p data-bind="text: MessageBody"></p>
</div>
</div>
</div>
</div>
The URL of the Image returned from WebAPI is Relative URL like ~/Content/Member/Image1.jpg. While its bind with Image URL shows like "http://sitename.com/profile/~/Content/Member/Image1.jpg".
Everything works great accept Profile Picture
I need to work something on binding as as I cannot change the Path coming from Database.
Appreciate your suggestions.
Regards,
Your binding looks okay. For starters I would use your IE or Chrome developer tools ( F12 ) and change the src manually of the image to find out what exactly works for you.
You say you recieve this: ~/Content/Member/Image1.jpg
Setting the src to this should work: /Content/Member/Image1.jpg
You can change your message object client-side like this, once you're sure what is needed, but I think this should suffice:
var MessageFrom = {
FromUserProfileId: self.FromUserProfileId,
FromUserName: self.FromUserName,
FromUserPictURL: self.FromUserPictURL.replace('~','')
}

Multiple file upload using prototype.js

Is there a way to upload file using pure prototype and ajax. I've searched for it on google but did't got any satisfactory result. Can anyone please help me out??
The easiest way to get an "Ajax" file upload to work is to use a keyhole iframe as the target for your form:
<form action="handler/url" enctype="multipart/form-data" target="keyhole" method="post">
<input type="file" multiple name="user_file[]" />
<input type="submit" id="upload" value="Upload">
</form>
<!-- style the following to be tiny/hidden -->
<iframe id="keyhole" src="about:blank"></iframe>
The trick with this is to show a waiting indicator, and hide it after the upload is complete.
<div id="waiting" style="display:none"></div>
<script type="text/javascript">
$('upload').observe('click', function(evt){
$('waiting').show();
});
</script>
In your file upload handler, return a text/javascript header and the following script after a successful upload:
var waiting = top.document.getElementById('waiting');
if(waiting) waiting.style.display = 'none';
Naturally, this will only work if both endpoints are on the same server, owing to Same Origin Policy.

Loading a codeigniter view with a form from inside another view

Using codeigniter, I've been trying to load a view inside of a foreach loop, as follows:
$posts = $this->postslibrary->getAllPosts();
foreach($posts as $post){
$home['content'][$i] = $this->load->view('post', $post['data'], true);
$i++;
}
$this->load->view('head');
$this->load->view('home', $home);
$this->load->view('footer');
Each of those post views looks a little like this:
<div class="postnum<?=$post_num?>">
<p>Posted by: <?=$poster_name?></p>
<p>Reply to: <?=$poster_name?></p>
<form>
<input type='text' />
<input type='submit' />
</form>
</div>
And they're being loaded mostly successfully in the 'home' view (which is below for thoroughness).
<div ="posts">
<?php
for($i=0;$i<$count;$i++)
{
echo($content[$i]);
}
?>
<div class="clear"></div>
<a href='/posts/browse/'>Load more items</a>
</div>
But my output ends up looking like:
<div class='posts'>
<div class='postnum1'>
<p>Posted By: Jim</p>
<p>Reply to Jim</p>
<input type='text' />
<input type='submit' />
</div>
</div>
Why are my form tags not coming through?
Check if you already have a form around the current form. Chrome is one of the browsers which doesn't accept this and removes the second form. Using a form in a form is bad practice and I suggest you find a different solution to do the form handling.
Slightly left-of-field answer, but have a look at CodeIgniter Form Generator. I've used it a couple of times and it seems pretty good for generating forms from an array. It's a bit tricky to get your head around it to begin with, but it works well once you've gotten into it.
The basic idea is that you implement a form controller from your ordinary controller, and then just output it in your view file. It might be a more elegant (and sustainable) solution to what you're trying.

Resources