Is there a way to post two images in a single post with UWP Community Toolkit?.
I think it is possible, you can check the official sample app of UWP Community Toolkit.
It has encapsulated the twitter apis in its service. And according to the Twitter developer documentation: Uploading Media, it is supported to upload maximum 4 photos in a tweet.
In a word, you can open the project of this sample app, and find SamplePages -> Twitter Service -> TwitterPage.xaml.cs, finally find the SharePictureButton_OnClick event and override the original code:
StorageFile picture = await openPicker.PickSingleFileAsync();
if (picture != null)
{
using (var stream = await picture.OpenReadAsync())
{
await TwitterService.Instance.TweetStatusAsync(TweetText.Text, stream);
}
}
to:
var pictures = await openPicker.PickMultipleFilesAsync();
int num = pictures.Count;
List<IRandomAccessStream> streams = new List<IRandomAccessStream>();
foreach (var picture in pictures)
{
var stream = await picture.OpenReadAsync();
streams.Add(stream);
}
await TwitterService.Instance.TweetStatusAsync(TweetText.Text, streams.ToArray());
Related
Im grabbing a picture from the gallery like described in the docs. that works, I can pick the pictures in my ios gallery and I am getting a full stream:
string localFilePath = System.IO.Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
MainThread.BeginInvokeOnMainThread(() =>
{
img_profilePic.Source = ImageSource.FromStream(() => localFileStream);
img_profilePic.IsVisible = true;
});
But when I try to set the image to the imagesource of my image from xaml, nothing changes in the UI.
If I change the image to a local image however, it updates the UI. So it must be something with the stream.
Anyone got any idea?
My Use Case:
Users in my app can create lists of items. I want the users to be able to share a link to one of their lists.
I want individuals who click the shared link to see the list of items in a web browser and not need the app installed.
Create the Dynamic Link
The first thing I need to do is create a dynamic link for a user to share. I struggled with this at first and then looked at this question here: Flutter - How to pass custom arguments in firebase dynamic links for app invite feature?
After looking at that I build my own class like so:
class PackDynamicLinkService {
Future<Uri> createDynamicLink({required String packID}) async {
final DynamicLinkParameters parameters = DynamicLinkParameters(
// This should match firebase but without the username query param
uriPrefix: 'ttps://appName.app/p',
// This can be whatever you want for the uri, https://yourapp.com/groupinvite?username=$userName
link: Uri.parse('https://appName.app/p?pack=$packID'),
androidParameters: const AndroidParameters(
packageName: 'com.test.demo',
minimumVersion: 1,
),
iosParameters: const IOSParameters(
bundleId: 'com.test.demo',
minimumVersion: '1',
appStoreId: '',
),
);
final dynamicLink = await FirebaseDynamicLinks.instance.buildShortLink(
parameters,
shortLinkType: ShortDynamicLinkType.unguessable,
);
return dynamicLink.shortUrl;
}
}
I then called that function in my app and I am able to get a URL that looks like this: https://appName.app/p?pack=lVeSBUHoLX52zPqAiB9A
So far so good. Now I just need to click the link and read the parameter $packID that I passed to it inside my web app. Then I can route them to the correct view and display the list.
Processing Dynamic Link
in my marin.dart I tried to retrieve the params with:
//get link stuff
final PendingDynamicLinkData? initialLink =
await FirebaseDynamicLinks.instance.getInitialLink();
if (initialLink != null) {
final Uri fullLink = initialLink.link;
print(fullLink.queryParameters['pack']);
}
but when I upload to firebase hosting to see if this code works for testing, I get this error:
Uncaught MissingPluginException(No implementation found for method
FirebaseDynamicLinks#getInitialLink on channel
plugins.flutter.io/firebase_dynamic_links)
After doing some more research it seems that firebase_dynamic_links package may not be available for web? So does that mean my original use case is not possible with flutter at this time?
You would want to take the link received and parse it using something like:
var PendingDynamicLinkData? initialLink =
await FirebaseDynamicLinks.instance.getInitialLink();
if (kIsWeb) {
String link = Uri.base;
initialLink = await
FirebaseDynamicLinks.instance.getDynamicLink(Uri.parse(link));
}
if (initialLink != null) {
final Uri fullLink = initialLink.link;
print(fullLink.queryParameters['pack']);
}
Here, we are checking if its a web app and then we can parse the dynamic link and get the info for it. We just check for the Uri that was used in our web app.
Currently, what I did is to access the camera and use it to take a picture, but this isn't exactly what I want to accomplish.
I want to activate and display front camera preview on my content page, and then take a picture by pressing a button control.
I've searched around and I can't seem to find any solution. In Xamarin, there's CameraView from Xamarin Community Toolkit that can be used for camera stream, but from the looks of it, CameraView hasn't been implemented in .NET MAUI Community Toolkit. Is there any other way to do this? Thank you.
This is the code for the button event
private async void takephoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
Stream stream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
DisplayPhoto.Source = ImageSource.FromStream(() =>
{
return stream;
});
}
}
}
In flutter for uploading image according to doc is
final avatarFile = File('path/to/file');
final response = await supabase
.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile, fileOptions: FileOptions(
cacheControl: '3600',
upsert: false
));
So, how we can get the downloadUrl of this uploaded media ?
You can use the getPublicUrl method:
final res = supabase
.storage
.from('avatars')
.getPublicUrl('public/avatar1.png');
final publicURL = res.data;
See https://supabase.com/docs/reference/dart/storage-from-getpublicurl
To receive downloadUrls of your uploaded media, you need to create a subscription to the media table.
The following snippet will create a subscription to the media table and log each media item as it is created:
mediaSubscription = supabase
.from('media')
.subscribe((event) {
print(event.doc.data);
});
I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn't provide controls to upload files.
Does PhoneGap provide any mechanisms that allow users to upload files? (images / video, in the case of the iPhone)
I know Titanium allows users to do this, but it's a different animal with its compiled Javascript and proprietary APIs. Thanks for your advice/input.
I believe you might be able to read the files using the PhoneGap API and the upload them using and AJAX post if the server application supported it.
The other option is to write a custom module/Plugin in PhoneGap that could specific to your needs.
Here are some Example Plugins
You can do an xmlhttprequest to the file on a local drive.
I'm not 100% sure if it will work on the iPhone, but webkit should support it.
function getImageBinaries(url) { //synchronous binary downloader for firefox2
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send("");
if (req.status != 200) {
return "";
}
var t = req.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
ff[z] = scc(t.charCodeAt(z) & 255);
}
var b = ff.join("");
return b;
}
Succes,
Erik