How to use uploading dropped and pasted images using CKeditor - image

I want to implement following using fuelPHP.
http://ckeditor.com/tmp/4.5.0-beta/image-upload.html
Then, I added all plugins and can upload the images to my directory.
However, I do know the format of the response for client side of CKEditor and so CKEditor is not able to locate file path.
Dose anyone know the format of its response?
I return the json object like following.
json_encode(array('responseText'=>'ok','uploaded'=>1,'fileName'=>"/assets/img/upload/d2ceb4f415e252199483ee96f5ba361d.png"),true);

The response should be like following
{
"uploaded": 1,
"fileName": "foo.jpg",
"url": "/files/foo.jpg"
}

Related

Is it possible to use a file path instead of url as `image_url` when sending a message via Slack API or Incoming Webhook?

Let's assume I have the following block which I want to send via Incoming Webhook to Slack
{
"type": "image",
"title": {
"type": "plain_text",
"text": "foo bar"
},
"image_url": "https://api.slack.com/img/blocks/example/beagle.png",
"alt_text": "foo"
}
but instead of providing a http url as image_url I would like to provide a file path because the file I want to send is in the same folder as my script.
1) Is this possible? I guess no.
2) Is it possible to upload an image via files.upload in a first step WITHOUT actually displaying is on any channel just to get the URL which then can be used as image_url?
1) No. As I mentioned earlier its not possible to use a file path to directly include an image in a message. The only way is to provide a public URL to an image file.
2) Yes, you can use files.upload you uploaded to Slack in your messages. And you do not have to share them in any channel do it.
The basic approach is:
Upload your image to Slack with files.upload. And if you do not provide any channels with that API call the file will not be shared in any channel. You will get the file object incl. the file ID of the uploaded image file.
Call files.sharedPublicURL to make that file public by providing the file ID
Your image file is now public and you can use the permalink_public of the file object to include that image in message. However, you still need to construct the direct URL for that image from the URL you get from permalink_public. Check out this post on how to get the direct URL for the image.

How to import grafana dashboard json file manually

I have exported the dashboard in json format.
I want to import the json file manually to create the same dashboard in new grafana instance.
While googling i got some related information but finding difficulties to implement successfully.
From the site Grafana API link i got the code snippet like,
POST /api/dashboards/db HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
“dashboard”: {
“id”: null,
“uid”: null,
“title”: “Production Overview”,
“tags”: [ “templated” ],
“timezone”: “browser”,
“schemaVersion”: 16,
“version”: 0
},
“folderId”: 0,
“overwrite”: false
}
The above code snippet looks like we can create new dashboard with existing json file but i have no idea of how to implement this code snippet successfully.
Somebody guide me how to achieve this?
There are two techniques to copy the current dashboard -
if you want to export this
Go to Current Grafana Dashboard
Select the Share button on the top
Select the Export Button and Copy the JSON or save it as JSON
Create new Grafana dashboard and copy this JSON model to
Click on the Setting button on the top
Click on JSON Model - from left panel
Past the JSON & Save the dashboard and run
Please let me know if you have any issue.
I found and answer to your question - how to import a dashboard in grafana by api - in this post on the community board of Grafana:
https://community.grafana.com/t/how-create-dashboard-and-panel-via-api/10947
Haven't tried this out yet though (we are planning on doing something like this as well).
I will quote the original question in this post:
Hi All,
I know how to create a dashboard via API but I don’t find instructions to how to create panels within that dashboard still via API. Any idea?
the part of the message that explains the answer:
And the response that contains the answer to the question:
The panels need to be defined within the JSON that you submit in your POST request.
The example in the docs doesn’t spell this out, beyond
dashboard – The complete dashboard model
To get hands-on with this, you can (1) create a new dashboard with some panels manually, (2) export that dashboard’s definition as JSON, (3) put the exported dashboard definition inside the “dashboard” field of a new JSON object, (4) POST the resulting JSON object to the API endpoint. This will create a copy of your original dashboard. From there on, you can edit the JSON model you’re posting in order to modify or add any panels you desire.
So to your original question, if you want to add a panel to an existing dashboard you can obtain its definition via the API, add the panel to the JSON object, and push the updated model. (keep the same id/uid and set "overwrite": true)"
Note that (now?) grafana has a nice import function too:

Uploading a JSON through Dropzone: acceptedFiles: doesnt recognise json

I am trying to upload a JSON through Dropzone.
The MIME type for JSON through acceptedFiles doesn't seem to be recognised.
Already tried:
acceptedFiles: 'application/json'; and
acceptedFiles: '.json';
When using 'application/json', dropzone doesnt recognise json file types so I am unable to upload a file.
When using '.json', I am able to upload a file but it turns into 'application/octet-stream'.
What do i need to use to upload a JSON and it be an accepted file type?
I fixed this by updating Google Chrome.

how to read text file from django server using ajax?

I wanna know how to read text file from django server using ajax? or something else.
I searched about using XMLHttpRequest and It worked when I tryed to get django template html file. but I couldn't get other text file outside of templates directory. how can I send content of requested file in veiw.py ??
I think I cant use render_to_response()..
I need your help:(
Simething like this in your url:
url(r'^static/mymedia/' , 'myproject.views.get_file'),
Something like this in your views:
def get_file(request):
current_directory='/home/arpit/myproject/'
f=open(current_directory+request.path)
return HttpResponse(f.read(),mimetype='text/plain')

Tincr for ASP.NET MVC 3

I am trying to use the tincr extension in chrome. It allows you to refresh css and javascript without having to reload the page again. I'm having some trouble getting it working and would appreciate any help.
My Setup
Source code root directory:
C:\dev\tfs\MyApp\Development Branches\3.3.0.0\Presentation\MyApp
IIS website directory points to the root directory above. The Scripts directory underneath the folder path above contains the js files that I am changing.
I created a tincr.json file and put it in the root directory
tincr.json
{
"toFile" : [],
"fromFile" : [
{"from": "C:\\\\dev\\\\tfs\\\\MyApp\\\\Development Branches\\\\3.3.0.0\\\\Presentation\\\\MyApp\\\\Scripts\\\\(.+\\.js)",
"to": "http://localhost/MyApp/Scripts/$1"}
]
}
Is this correct? Has anyone managed to get tincr working with ASP.NET MVC 3? Thank you for your help.
PS - I don't have the rep to create a tincr tag so if someone could add that to this it would make it easier for others to post questions about it too. Thanks.
After playing around and reading google groups and other web sites I pieced together the following
Tincr does not work with query parameters in windows (eg. common.js?var=1 will fail)
You need to be careful of ajax queries that append to the url for js files that come from references to ajax code. Use Fiddler and watch the URLS. I had to make sure that the js file was added to the _Layout.cshtml file and then it would come out without query parameters.
I put a more detailed how to for Tincr on my website http://aboutdev.wordpress.com/2013/01/26/using-tincr-with-asp-net-mvc-in-windows-7/ but here is what you need.
The tincr.js file I used looks as follows:
{
"toFile" : [],
"fromFile" :
[
{
"from": "\\\\Scripts\\\\([a-zA-Z]+)\\.js",
"to": "/MyApp/Scripts/$1.js"
}
]
}
This file does not update the file on disk because 'tofile' is not filled in.
This file will look for files in the Scripts directory that is directly under the root where you put your tincr.json file.
I hope this helps you with using Tincr in your pojects.

Resources