No JSON web service action associated with path /dlapp/add-file-entry and method POST liferay 6.2.4 - liferay

Here is my code to upload document in liferay via jsonapi. i am adding file inside document liberary. But it show error "No JSON web service action associated with path /dlapp/add-file-entry". I am using liferay 6.2.4 ga5.
Thanks
<html>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$( document ).ready(function() {
$("#submit").click(function(e) {
e.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
url: 'http://localhost:8080/api/jsonws/dlapp/add-file-entry?repositoryId=27058&folderId=34530&sourceFileName=Screenshot&mimeType=image/png&title=hello&description=test&changeLog=not',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
success: function (response) {
alert(response);
}
});
});
});
</script>
<form>
<input type="file" name="file"/>
<input type="button" value="submit" id="submit"/>
</form>
</html>

Liferay JIRA
You could be encountering LPS-31943. It was a known issue related to this resource action. Please use the patching tool to upgrade to the latest patch version. I see in the comments that users are stating this problem still persists despite the bug being closed in some versions of Chrome.
Error Message
This error message is most commonly seen when you are missing required data from the request. Assuming you are fully patched, it is very likely that your data object is not correct. Even though you are sending the data as query parameters (which could be an issue depending on your JSON WS properties), the data object is still wrong and is therefore giving you the error message.
The HTTP Request
Firstly, Is there a particular reason you are calling the service this way? I believe you can achieve a better result using only HTML
<form action="http://localhost:8080/api/jsonws/dlapp/add-file-entry" method="POST" enctype="multipart/form-data">
<input type="hidden" name="repositoryId" value="27058"/>
<input type="hidden" name="folderId" value="34530"/>
<input type="hidden" name="title" value="hello"/>
<input type="hidden" name="description" value="test"/>
<input type="hidden" name="changeLog" value="not"/>
<input type="file" name="file"/>
<input type="submit" value="addFileEntry(file)">Submit</input>
</form>
This code is taken from the official Liferay knowledge base and adapted for your specific example. If you insist on using jQuery you need to stringify your data object. I would do something like this.
<html>
<head></head>
<body>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$( document ).ready(function() {
$("#submit").click(function(e) {
e.preventDefault();
var formData = JSON.stringify($("form:first").serializeArray());
$.ajax({
url: 'http://localhost:8080/api/jsonws/dlapp/add-file-entry',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
success: function (response) {
alert(response);
}
});
});
});
</script>
<form>
<input type="hidden" name="repositoryId" value="27058"/>
<input type="hidden" name="folderId" value="34530"/>
<input type="hidden" name="title" value="hello"/>
<input type="hidden" name="description" value="test"/>
<input type="hidden" name="changeLog" value="not"/>
<input type="file" name="file"/>
<input type="button" value="submit" id="submit"/>
</form>
</body>
</html>
Best Practice
The sample's above are fine if you are invoking this service from an external application. If, however, you are invoking this from inside the portal (a JavaScript portlet for example) I would definitely utilize Liferay's JavaScript API and the AlloyUI tag libraries.
Liferay.Service(
'/dlapp/add-file-entry',
{
repositoryId: 12345,
folderId: 2345,
sourceFileName: 'Screenshoot',
mimeType: '',
title: '',
description: '',
changeLog: '',
cmd: {"/dlapp/add-file-entry":{}},
file: null
},
function(obj) {
console.log(obj);
}
);
Also if you are building something new you be using Liferay 7 or DXP as it is much more current.

Related

Wrong barcode being scanned into a web form in Chrome?

For some reason, abour 50% of the time, if I scan a standard book ISBN barcode into Chrome, it will read 9781782941972 as 9780008134372?!
We have a web based data management system with a web form that requires a barcode. It will then return the book's data to another div. It's worked for years but over the past few months it's started reading the wrong barcodes.
The html looks like this...
<form id="location_lookup" name="location_lookup" method="get" style="float:left;">
<div style="float:left;clear:left;margin-bottom:10px;">
<label for="isbn13">Barcode/Product Code :</label>
<input id="isbn13" name="isbn13" type="text" value="" />
<input id="isbn13" name="function" type="hidden" value="lookupProduct" />
</div>
<div style="float:left;clear:left;">
<input type="submit" value="Send" class="bigbutton" />
<input type="reset" value="Clear" id="formReset" class="bigbutton"/>
</div>
</form>
so the input with id isbn13 has a 13-digit number dumped into it by a simple barcode scanner. The barcode scanner is set to enter a CR after the barcode is dumped (and hence submit the form). Then this runs...
$("#location_lookup").submit(function(event) {
event.preventDefault();
var isbn13 = $("input[name='isbn13']").val();
$.ajax({
url: "location_functions.php",
type: "get",
data: values,
async: false,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
dataType: "json",
success: function(values){
//does more stuff...
It's a boring, perfectly normal barcode reader that's being scanned into a basic PHP web input. I've tried swapping over the scanners but it still seems to happen. I've also tried disabling the anti-virus but again, it still happens!
I just don't get what's happening!

How do you use a signed policy from google-cloud/storage to upload data?

ref:
https://cloud.google.com/nodejs/docs/reference/storage/1.5.x/File#getSignedPolicy
I am trying to upload files to my bucket using signed policies. Using the example from the documentation I get a response from my bucket object for 3 items.
"policyString": "{\"expiration\":\"2019-10-18\",\"conditions\":[[\"eq\",\"$key\",\"image.jpg\"],{\"bucket\":\"my-bucket\"},[\"eq\",\"$Content-Type\",\"image/jpeg\"],[\"content-length-range\",0,1024]]}",
"policyBase64": "[some-long-string]",
"policySignature": "[some-long-string]"
In the documentation it also shows you how to upload objects using curl.
ref:
https://cloud.google.com/storage/docs/object-basics#upload-object-json
How do you assemble what I get back as a signed policy and the upload api
https://www.googleapis.com/upload/storage/v1/b/[BUCKET_NAME]/o?uploadType=media&name=[OBJECT_NAME]
to upload a file to my bucket using axios? Is there other headers to attach?
Here is what I did to take a stab at it but I'm not sure.
const options = {
headers: {
'Authorization': ?
'Content-Type': file.type
}
}
axios.put(concatenatedPolicySignatureUrl, file, options)
.then(response => {
console.log('success!');
}
Signed policy strings only work with the XML API, which means POSTs to https://storage.googleapis.com/bucket/object (and not www.googleapis.com/upload).
For more on exactly how to generate and use the policy, see https://cloud.google.com/storage/docs/xml-api/post-object#policydocument
An example of setting up an HTTP form that would allow a user to upload an object using a policy string is below, although you could also trigger an equivalent POST request via JavaScript:
<form action="http://travel-maps.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="">
<input type="hidden" name="bucket" value="travel-maps">
<input type="hidden" name="Content-Type" value="image/jpeg">
<input type="hidden" name="GoogleAccessId" value="1234567890123#developer.gserviceaccount.com">
<input type="hidden" name="acl" value="bucket-owner-read">
<input type="hidden" name="success_action_redirect" value="http://www.example.com/success_notification.html">
<input type="hidden" name="policy" value="eyJleHBpcmF0aW9uIjogIjIwMTAtMDYtMTZUMTE6MTE6MTFaIiwNCiAiY29uZGl0aW9ucyI6IFsNCiAgWyJzdGFydHMtd2l0aCIsICJrZXkiLCAiIiBdLA0KICB7ImFjbCI6ICJidWNrZXQtb3duZXItcmVhZCIgfSwNCiAgeyJidWNrZXQiOiAidHJhdmVsLW1hcHMifSwNCiAgeyJzdWNjZXNzX2FjdGlvbl9yZWRpcmVjdCI6ICJodHRwOi8vd3d3LmV4YW1wbGUuY29tL3N1Y2Nlc3Nfbm90aWZpY2F0aW9uLmh0bWwiIH0sDQogIFsiZXEiLCAiQ29udGVudC1UeXBlIiwgImltYWdlL2pwZWciIF0sDQogIFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLCAwLCAxMDAwMDAwXQ0KICBdDQp9">
<input type="hidden" name="signature" value="BSAMPLEaASAMPLE6SAMPLE+SAMPPLEqSAMPLEPSAMPLE+SAMPLEgSAMPLEzCPlgWREeF7oPGowkeKk7J4WApzkzxERdOQmAdrvshKSzUHg8Jqp1lw9tbiJfE2ExdOOIoJVmGLoDeAGnfzCd4fTsWcLbal9sFpqXsQI8IQi1493mw=">
<input name="file" type="file">
<input type="submit" value="Upload">
</form>

cant make the gmaps.js search functions

i have made this simple app with gmaps.js but i need the search functions like they show it here:
http://hpneo.github.io/gmaps/examples/geocoding.html
i looked at the source code and all but it aint working.. The search button reloads the page...
my code is a follows:
<script>
$('#geocoding_form').submit(function(e){
e.preventDefault();
GMaps.geocode({
address: $('#address').val().trim(),
callback: function(results, status){
if(status=='OK'){
var latlng = results[0].geometry.location;
map.setCenter(latlng.lat(), latlng.lng());
}
}
});
});
</script>
<form method="post" id="geocoding_form">
<label for="address">Address:</label>
<div class="input">
<input type="text" id="address" name="address" />
<input type="submit" class="btn" value="Search" />
</div>
</form>
<div id="map"></div>
the rest is loaded in from scripts.js you can see it in sourcecode. Why is this happening and how can i fix this?
The web app is located here, http://travelers.work/trein/
You need to change
map.setCenter(latlng.lat(), latlng.lng());
to
map.setCenter(latlng);
because the search returns a LatLng object as a result, and that's what is needed as an input for setCenter.
Here's a JS demo with your code: http://jsfiddle.net/DuRhR/3/
EDIT after comments:
Alternatively, you can pass to setCenter a LatLngLiteral
map.setCenter({lat: latlng.lat(), lng: latlng.lng()});

Can't update user model in express?

I'm trying to do a put request to update a user model but instead my router just sends another get request.
Here's my router
router.get('/update', isLoggedIn, function(req, res) {
res.render('update.ejs', {
user : req.user // get the user out of session and pass to template
});
});
router.put('/update', function(req, res) {
var username = req.body.username;
var profile_type = req.body.prof_type;
var pic = req.body.profile_pic;
var aboutme = req.body.whoami;
console.log(req.body.whoami);
User.findById(req.params.id,function(err, userup){
if (!userup)
return next(new Error("Couldn't load user"));
else {
userup.username = username;
userup.prof_type = profile_type;
userup.profile_pic = pic;
userup.whoami = aboutme;
userup.save(function(err) {
if (err)
console.log('error on update');
else
console.log('successful update');
});
}
});
res.redirect('/profile');
});
Here's my html input form
<form action="/update" method="put">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" name="username">
</div>
<div class="form-group">
<h2> Pick a type of profile</h2>
<input type="radio" class="form-control" name="prof_type" value="true">Tutor<br>
<input type="radio" class="form-control" name="prof_type" value="false">Student
</div>
<div class="form-group">
<label>Link to profile picture</label>
<input type="text" class="form-control" name="profilepic">
</div>
<div class="form-group">
<label>About me</label>
<textarea name="whoami" class="form-control">Enter text here </textarea>
</div>
<button type="submit" class="btn btn-warning btn-lg">Update</button>
</form>
I've also tried changing them to be /update/:username, however, after I click the update button with the fields, I GET this address
http://localhost:3000/update?username=bob&prof_type=false&profilepic=bob&whoami=bob
Not sure why I'm not updating the model or even why it's not putting. Any help is much appreciated, thanks!
HTML only supports GET and POST requests. See the specification for details:
The method and formmethod content attributes are enumerated attributes
with the following keywords and states:
The keyword get, mapping to the state GET, indicating the HTTP GET
method. The keyword post, mapping to the state POST, indicating the
HTTP POST method. The invalid value default for these attributes is
the GET state. The missing value default for the method attribute is
also the GET state. (There is no missing value default for the
formmethod attribute.)
You can use the PUT method only with an ajax request. For example in jQuery:
$.ajax({
url: '/update',
type: 'PUT',
success: function(result) {
// Do something with the result
}
});

Shortcut to adding req values to a response for rendering in Express View

I'm using Node/Express (most recent production versions)
I have a form where I collect new account info. The user can add a username, etc.
In the view handler, I check a mongodb database to see if the username is unique. If it is not, I generate a message and reload the original view. Since the original request was a post, all of the data the user posted is in req.body. I would like to add the data the user submitted on the response. I could do it by specifically adding each value to the response. But isn't there an easier way to add all the request data back to the response? And is there a way to render that in the view (i'm using ejs) I tried res.send(JSON) coupled with ejs variables. Doing so generates errors saying the variables aren't available.
Here's my function (ignore the users.createUser(req) - it's not finished yet):
createAccount: function(req, res, next){
users.createUser(req);
res.render('create_account', {
layout: 'secure_layout',
title: 'Create Account',
givenName: req.body.givenName,
username: req.body.username,
familyName: req.body.familyName
});
},
And here's my view:
<form action="/createAccount" method="post">
<div>
<label>First Name:</label>
<input type="text" name="givenName" value="<%= givenName %>"/><br/>
</div>
<div>
<label>Last Name:</label>
<input type="text" name="familyName" value="<%= familyName %>"/><br/>
</div>
<div>
<label>Username:</label>
<input type="text" name="username" value="<%= username %>"/><br/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="Submit"/>
</div>
</form>
It seems overly complex to have to add each of the values. I tried {body: req.body} but values were never added to the view.
I'm not quite sure what you're after, but if you want to render an ejs view with data that was on the request body, you would do something along these lines:
app.post('/foo', function(req, res, next) {
res.render('view', {body: req.body});
});
view.ejs:
<ul>
<% for(var key in body) { %>
<li><%= key %>: <%= body[key] %></li>
<% } %>
</ul>

Resources