VOLUME XCII             08/04/2021

Working With Files in the Ninox API

By Adam Davidson, Director of Product Development

This Article will be part of a series of articles which will explain how to use the Ninox API to work with files that are attached to records in Ninox.

There may come a situation where you need to deal with file attachments via the API rather than using Ninox functions. To demonstrate how a file upload is done with the API, we will create a file selector and uploader in Javascript which will be placed in a formula function in Ninox.

Place the following code in a formula function in Ninox:

				
					html(" <script>function uploadFile(){let file=event.target.files[0];let formData=new FormData();formData.append('file',file);let url='https://api.ninox.com/v1/teams/" + teamId() + "/databases/" + databaseId() + "/tables/" + tableId(this) + "/records/" + Id + "/files';fetch(url,{method:'POST',body:formData,headers:{'Authorization':'Bearer " + apiKey() + "'}})}</script> <form>
	<input type=file onchange='uploadFile()'></input>
</form>
")
				
			

The code above creates a form with a file selector button. When a file is selected , the function “uploadFile()” sends the file to the Ninox API. The function is called in the onchange function for the input element, so the upload will occur as soon as the file is selected. The code will attach the file to the current record.

Note that we have used the global function apiKey() to access the API key here for security. You will have to replace this with your own API key if you use it in your database.

The body of the HTTP request being sent to Ninox needs to be in a particular format when sending files. The above code uses the browser’s built in FormData() object to make sure that the call is made in the correct way. When a FormData object is passed into the body of a fetch() request, a few headers are added to the request which are necessary for the form to be sent correctly.

In this case it is just as easy to go to the attachments and upload the file there. This method will work well when you would like a central location from which you would like to upload files, or you would like to create a custom file upload button.  Next time we will look at more applications of the files API.  

Office 365 Integration and Team Collaboration Coming Soon to DocumentsPLUS!

Learning Lab

Join us this Thursday at 12:00pm ET or 6:00pm CET where we’ll be doing an open Q&A! Be sure to bring your questions for us! And don’t forget, asking questions will earn you Gold Stars!

Gold stars can be redeemed at the end of the year for prizes, so try and earn as many stars as you can! For more information about the Gold Star Program, click here.

Check Out Our Templates

Did you know that Nioxus has built over 130 templates which are available to all Standard, Deluxe and Premier Nioxus members?

Nioxus University YouTube Channel

Nioxus has created nearly 100 videos and over 200 hours of content teaching you how to use and optimize Ninox, as well as our supplementary products, CalendarPLUS, ReportsPLUS and DocumentsPLUS!

Upcoming Additions to CalendarPLUS

Michael Sidenstick, Programmer/Developer

As you likely already know, CalendarPLUS is Nioxus’ innovative calendar upgrade to Ninox. We here at Nioxus have some new looks at some upcoming quality of life updates to CalendarPLUS. These upcoming changes include an updated search functionality, the ability to zoom to a specific date, and a reworking of some of the fields within events on the calendar.
Previously, a limitation of CalendarPLUS was the inability to search for specific fields within an event. For instance, if an event had a location listed as “Cincinnati” and you only wanted to filter for events located in Cincinnati, this previously was not possible. With the upcoming changes to CalendarPLUS, we are adding the ability to search under any field within an event, including multiple choice fields and any custom fields specific to your databases. This change should make searching through large amounts of events far easier. The next addition to CalendarPLUS is a new functionality allowing users to zoom to any date on the calendar by using a date-picker built into the toolbar, pictured here.
This new functionality is great for adding new events in the distant future, as navigating through years or multiple months of the calendar was not previously possible. Instead of having to click through every month to view other years, now a user can simply zoom to a date using the intuitive date-picker. Finally, the upcoming CalendarPLUS changes have made adding information into the events much more intuitive. Now, CalendarPLUS will use a new time-picker for setting the hours of an event, and making events last a full day or multiple days is much easier. CalendarPLUS has always been a powerful tool for any Ninox database, and we hope that these upcoming changes will improve users’ ease of usage with CalendarPLUS and promote efficient and simpler use. Look out for these changes in the upcoming weeks!

Top Technology Trends, Treasures and Triumphs

World’s Thinnest Magnet is One Atom Thick!

The world’s thinnest magnet that operates at room temperature could advance new applications in computing and electronics.  This one atom thin 2D magnet was recently reported in the journal, Nature Communications and was developed by the Lawrence Berkeley National Laboratory and UC Berkeley.  According to senior author Jie Yao, a faculty scientist in Berkeley Lab’s Materials Sciences Division and Associate Professor of Materials Science and Engineering at UC Berkeley, “We are the first to make a room-temperature 2D, magnet that is chemically stable under ambient conditions.”  Yao goes on to say, “It opens up every single atom for examination, which may reveal how quantum physics governs each single magnetic atom and the interactions between them.”This design was created by using a technique that the team says is easily expandable and features a single atomic layer of zinc oxide, with occasional cobalt atoms interspersed within it. The free electrons of zinc oxide maintain the magnetism of cobalt while using the basic mechanism that is different from all other attempts to create 2D magnets.  “With our material, there are no major obstacles for industry to adopt our solution-based method”, says Yao.  “It’s potentially scalable for mass production at lower costs.”“Our results are even better than what we expected, which is really exciting. Most of the time in science, experiments can be very challenging,” Yao said. “But when you finally realize something new, it’s always very fulfilling”

All of you keep your eyes out for new tools for the study of quantum physics as well as high-density, compact spintronic memory devices.  We are all on the precipice of some extremely exciting technology in the upcoming months and years.

Journal reference: Nature
https://www.nature.com/articles/s41467-021-24247-w

https://newscenter.lbl.gov/2021/07/20/worlds-thinnest-magnet/

Copyright 2021 © All Rights Reserved.

All logos, trademarks and names are the protected property of Nioxus Corporation or their respective owners.

“Ninox,” “Ninox Database” and the blue Ninox owl eye logo are the property of Ninox Berlin and are used with permission.

en_USEN