How can I upload post without photo in this code? (Flutter&Firebase) - flutter

I made code which upload the post on Firebase.
This code is the upload code.
but I don't know how to upload a post with no photo.
When posts include photos, I can upload them to firebase, but I can't upload without a photo.
code link: https://github.com/HighschoolStudentDeveloperYoon/Q1

In your _uploadFile method first check if the file variable has content;
if (_image != null) {
//put file to your storage and retrieve downloadURL
}
& if it doesn't have any content just pass null to your Firestore 'photoUrl' key.

Related

Upload image to meta ads using marketing api

I am trying to upload an image, get the image hash for use in creating an adcreative using meta marketing api on google colab, but i keep getting an empty list, don't know why that keeps happening.
i have properly authenticated and i am able to post ad campaigns, adsets remotely but i am unable to upload and image or view list of existing images/hash
path = '/content/drive/Shareddrives/Design/sampleimage.png'
image = AdImage('act_5**********')
image[AdImage.Field.filename] = path
image.remote_create()
image_hash = image[AdImage.Field.hash]
print(image)
even when i try to read the existing adimages i also get an empty lsit.
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('act_5**********')
fields = ['id','hash','name','original_height','original_width']
images = my_account.get_ad_images(fields=fields)
images
try uploading your images as .bmp, .jpeg, or .gif:

Update Firebase database object with multiple uploads

I have a post object that has two parts (1)photo and (2)video. In the posting flow the user selects and image, then hits next to the next screen where they select a video. Both the photo and the video are uploaded to Firebase as part of a post object. See the simple design.
wireframe design
I'm getting stuck creating the post object with both the photo url and the video url. I've tried:
1- After selecting the photo and moving to the next step, I upload the photo to Firebase storage and create the post object in the database with the photo url and an empty string for the video url.
2-Then after selecting the video, I upload the video to Firebase storage, and try to update the existing post object with the video url...
However I have not been able to update the correct post object, and don't know how I can retrieve the postByAutoID in order to update the correct post.
Here is what the database object looks like:
I tried to pass the photoURL forward to the second part of the post, but the upload and generation of the url is not complete by the time the variable gets passed.
Any help is appreciated!
With web, or JavaScript, uploads to firebase cloud storage return promises, therefore Promise.all an array of individual uploads.
As for swift, or IOS, you will have to push each upload (.putData) to memory then iterate/loop over them.
See Upload Files on iOS which provides a starting point and add your loop/iteration.
// Data in memory
let data = Data()
// Create a reference to the file you want to upload
let riversRef = storageRef.child("images/rivers.jpg")
// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can also access to download URL after upload.
riversRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
}
}

Set a playlist picture using the Deezer JS API

My client would like to create playlists on Deezer, and also add their own pictures against their creations.
I have a simple playlist creation call, using the Deezer JS SDK:
playlistObj = // already created object with title,
// description, images array and
// array of Deezer track IDs
DZ.api('user/me/playlists', 'POST',
// fields object
{
title : playlistObj.name,
picture_small: playlistObj.images[2].url,
picture_medium: playlistObj.images[1].url,
picture_big: playlistObj.images[0].url,
},
function (response) {
DZ.api('playlist/'+response.id+'/tracks', 'POST',
{ songs: playlistObj.tracks },
function (playlistTracksResponse) {
console.log(playlistTracksResponse); // true
}
);
}
);
The playlist and tracks create fine and I can see them on my account. However, the picture urls I'm setting and passing in the fields object and not being used by Deezer. Do the images need to be in a specific format? Do they need to be in a specific size? Can you only set images with a specific account type?
The documentation doesn't suggest that picture uploading is precluded, and I've tried various combinations of images from google image searches, of jpg, png and of a variety of sizes, including 200x200px as I can see on their site.
Any help?
I'm sorry, what you're trying to do isn't supported by the API. When you create a playlist, the only field you can set is title.
Call https://api.deezer.com/infos, you will get a JSon with un upload token.
Send a POST as form_data with a key « file » with your image content on https://upload.deezer.com/playlist/{playlistId}?access_token={accessToken}&upload_token={uploadToken}

upload picture on timeline album of user using facebook c# sdk

I want to upload picture to timeline of user or page.
I am able to upload picture to users wall but it has created new album with my application name. But i want to upload picture to timeline album of user.
I have uploaded picture using bellow code
var result = client.Post("/"+ id +"/photos", postparameters);
I solved it.I just filtered id of the album where I wanted to post picture & passed it in place if "id" of above code.
var result = client.Post("/"+ album_id +"/photos", postparameters);
you can get album id dynamic :
dynamic albums = app.Get("me/albums");
string AlbumId="";
foreach (dynamic albumInfo in albums.data)
{
if(albumInfo.name == "Timeline Photos"){AlbumId=albumInfo.id; break;}
}
and the you can use AlbumId to post in the album .
msm2020 solution do the trick but don't forget to add the albums permission: user_photos

How to determine if a Facebook user has uploaded a profile picture or its default?

Is there a way to know if a user uploaded an image to the profile or it has the default user picture of Facebook via FQL or somthing else?
If a user doesn't have a photo then the is_silhouette field will be true when you request the user object with the "photo" field specified.
Example request:
https://graph.facebook.com/username?fields=picture
Response:
{
"id": "100002095576350",
"picture": {
"data": {
"url": "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",
"is_silhouette": true
}
}
}
Quick, dirty PHP function:
function facebook_user_has_photo($username_or_id){
$request = file_get_contents('https://graph.facebook.com/'.$username_or_id.'?fields=picture');
if($request):
$user = json_decode($request);
if($user && !$user->picture->data->is_silhouette) return true;
endif;
return false;
}
You can use the Python script below (as not mentioned any programming language) to make it work.
urllib.urlopen('https://graph.facebook.com/<PROFILE_ID>/picture?access_token=%s' % access_token).geturl()
This will provide you a Facebook profile photo URL. If that URL contains <PROFILE_ID> then it uploads an image. Else the default Facebook image is uploaded.
For example, if uploaded image:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/195361_<PROFILE_ID>_4179703_q.jpg
else:
For male:
http://b.static.ak.fbcdn.net/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif
For female:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/y9/r/IB7NOFmPw2a.gif
I hope this helps.
From my experiments with the Facebook API, it appears one has to actually get the picture in order to tell whether it's a static default one or not.
At the time of writing, it appears that all uploaded photos on Facebook are converted to JPEG, while the static default pictures are in the GIF format. (BTW, this is not consistent with some thumbnail sizes).
Looking for specific GIF file or a specific URL path is not reliable (note that there are CDN URLs involved, and that there are different static files for male and female). Assuming Facebook doesn't re-encode their entire profiles photos database, I suppose looking for a GIF is reliable enough.
Here's a sample PHP function to do this. I've tested it successfully with my 120 Facebook friends, and it seems to do the job.
public static function hasProfilePicture($fbuid)
{
/* Really stupid method to test if Facebook user has real profile picture
* based on Facebook returning a GIF image when you request a large photo.
* Use with care - for every profile there's an outgoing request! */
$r = get_headers("http://graph.facebook.com/$fbuid/picture?type=square");
return !array_search("Content-Type: image/gif",$r);
}