我们正在使用rocketchat嵌入式URL将聊天添加到我们的应用程序android和ios
我们需要的控件是上传图像,录制视频,录制音频
图片和视频效果很好
问题是iPhone中的布局未显示麦克风按钮
在android中工作正常
谁能告诉我原因是什么?
Rocket.Chat服务器版本:2.4.0
作业系统:linux
部署方式:tar
正在运行的实例数:1
DB Replicaset Oplog:已启用
NodeJS版本:v8.17.0
MongoDB版本:4.0.14
最佳答案
我花了很长时间尝试找出解决此问题的方法,但由于某种原因,由于某些原因,iOS阻止了上传文件,因此它是特定于平台的(具有UIWebView的iOS或新的WKWebView), (音频,视频...)使用这两个 View 。
如果尝试在iOS-Chrome上打开“火箭聊天”嵌入式布局,则会遇到相同的问题,但是,如果使用Safari打开它,则会注意到所有功能都正常(正在上传文件,音频,视频...)。
因此,尽管有一些牺牲UI的代价,但仍可以使我们的生活变得更轻松。
您需要开发一种功能来录制语音或视频(如果您愿意)并将音频/视频文件保存在某个位置,然后使用Rocket Chat API将其上传到所需的 channel 。
上传时,您需要告诉火箭聊天后端文件的类型。这是解决方案:
private void SendFileToRocketChat(string groupId, string filePath, string fileType)
{
var url = "your-rocket-chat-domain.com" + "/api/v1/rooms.upload/" + groupId;
string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.Method = "POST";
request.KeepAlive = true;
request.Headers.Add("X-Auth-Token", UserAuth); //your user 'admin' authentication token
request.Headers.Add("X-User-Id", UserId); //your user 'admin' authentication user ID
Stream memStream = new System.IO.MemoryStream();
var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--");
string formdataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
string headerTemplate = "Content-Disposition: form-data; name=\"file\"; filename=\"{1}\"\r\n" + "Content-Type: " + fileType + "\r\n\r\n";
memStream.Write(boundarybytes, 0, boundarybytes.Length);
var header = string.Format(headerTemplate, "file", filePath);
var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
memStream.Write(headerbytes, 0, headerbytes.Length);
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
var buffer = new byte[1024];
var bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
memStream.Write(buffer, 0, bytesRead);
}
}
memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
request.ContentLength = memStream.Length;
using (Stream requestStream = request.GetRequestStream())
{
memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
}
using (var response = request.GetResponse())
{
Stream stream2 = response.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
string res = reader2.ReadToEnd();
}
}
SendFileToRocketChat("yourgroupID","/file/audio/sample.mp3","audio/mp3");
SendFileToRocketChat("yourgroupID","/file/video/sample.mp4","video/mp4");
我希望这将成为一种解决方法,直到我们为该问题找到合适的解决方案。
关于ios - Rocketchat Embedded Layout在iPhone(iOS)中未显示麦克风按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59826021/